MongoDB C++ Driver  legacy-1.1.2
bson_extract.h
1 /* Copyright 2012 10gen Inc.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <string>
19 #include <vector>
20 
21 #include "mongo/base/status.h"
22 #include "mongo/base/string_data.h"
23 #include "mongo/bson/bsontypes.h"
24 
25 namespace mongo {
26 
27 class BSONObj;
28 class BSONElement;
29 class OID;
30 
37 Status bsonExtractField(const BSONObj& object,
38  const StringData& fieldName,
39  BSONElement* outElement);
40 
49 Status bsonExtractTypedField(const BSONObj& object,
50  const StringData& fieldName,
51  BSONType type,
52  BSONElement* outElement);
53 
62 Status bsonExtractBooleanField(const BSONObj& object, const StringData& fieldName, bool* out);
63 
74 Status bsonExtractIntegerField(const BSONObj& object, const StringData& fieldName, long long* out);
75 
84 Status bsonExtractStringField(const BSONObj& object, const StringData& fieldName, std::string* out);
85 
94 Status bsonExtractOIDField(const BSONObj& object, const StringData& fieldName, OID* out);
95 
106 Status bsonExtractBooleanFieldWithDefault(const BSONObj& object,
107  const StringData& fieldName,
108  bool defaultValue,
109  bool* out);
110 
121 Status bsonExtractIntegerFieldWithDefault(const BSONObj& object,
122  const StringData& fieldName,
123  long long defaultValue,
124  long long* out);
125 
136 Status bsonExtractStringFieldWithDefault(const BSONObj& object,
137  const StringData& fieldName,
138  const StringData& defaultValue,
139  std::string* out);
140 
149 Status bsonExtractOIDFieldWithDefault(const BSONObj& object,
150  const StringData& fieldName,
151  const OID& defaultValue,
152  OID* out);
153 
154 } // namespace mongo
Status bsonExtractIntegerFieldWithDefault(const BSONObj &object, const StringData &fieldName, long long defaultValue, long long *out)
Finds an element named "fieldName" in "object" that represents an integral value. ...
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
Status bsonExtractBooleanFieldWithDefault(const BSONObj &object, const StringData &fieldName, bool defaultValue, bool *out)
Finds a bool-like element named "fieldName" in "object".
Status bsonExtractOIDFieldWithDefault(const BSONObj &object, const StringData &fieldName, const OID &defaultValue, OID *out)
Finds an OID-typed element named "fieldName" in "object" and stores its value in *out.
Status bsonExtractBooleanField(const BSONObj &object, const StringData &fieldName, bool *out)
Finds a bool-like element named "fieldName" in "object".
Status bsonExtractTypedField(const BSONObj &object, const StringData &fieldName, BSONType type, BSONElement *outElement)
Finds an element named "fieldName" in "object".
BSONType
the complete list of valid BSON types see also bsonspec.org
Definition: bsontypes.h:38
Status bsonExtractField(const BSONObj &object, const StringData &fieldName, BSONElement *outElement)
Finds an element named "fieldName" in "object".
Status bsonExtractStringField(const BSONObj &object, const StringData &fieldName, std::string *out)
Finds a string-typed element named "fieldName" in "object" and stores its value in "out"...
Status bsonExtractOIDField(const BSONObj &object, const StringData &fieldName, OID *out)
Finds an OID-typed element named "fieldName" in "object" and stores its value in "out".
Status bsonExtractIntegerField(const BSONObj &object, const StringData &fieldName, long long *out)
Finds an element named "fieldName" in "object" that represents an integral value. ...
MONGO_CLIENT_API Status(MONGO_CLIENT_FUNC *saslClientAuthenticate)(DBClientWithCommands *client
Attempts to authenticate "client" using the SASL protocol.
Status bsonExtractStringFieldWithDefault(const BSONObj &object, const StringData &fieldName, const StringData &defaultValue, std::string *out)
Finds a string element named "fieldName" in "object".