MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
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
25namespace mongo {
26
27class BSONObj;
28class BSONElement;
29class OID;
30
38 const StringData& fieldName,
39 BSONElement* outElement);
40
50 const StringData& fieldName,
51 BSONType type,
52 BSONElement* outElement);
53
62Status bsonExtractBooleanField(const BSONObj& object, const StringData& fieldName, bool* out);
63
74Status bsonExtractIntegerField(const BSONObj& object, const StringData& fieldName, long long* out);
75
84Status bsonExtractStringField(const BSONObj& object, const StringData& fieldName, std::string* out);
85
94Status bsonExtractOIDField(const BSONObj& object, const StringData& fieldName, OID* out);
95
107 const StringData& fieldName,
108 bool defaultValue,
109 bool* out);
110
122 const StringData& fieldName,
123 long long defaultValue,
124 long long* out);
125
137 const StringData& fieldName,
138 const StringData& defaultValue,
139 std::string* out);
140
150 const StringData& fieldName,
151 const OID& defaultValue,
152 OID* out);
153
154} // namespace mongo
BSONElement represents an "element" in a BSONObj.
Definition bsonelement.h:55
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representa...
Definition bsonobj.h:78
Object ID type.
Definition oid.h:60
Status represents an error state or the absence thereof.
Definition status.h:50
A StringData object wraps a 'const string&' or a 'const char*' without copying its contents.
Definition string_data.h:43
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20
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.
Status bsonExtractBooleanField(const BSONObj &object, const StringData &fieldName, bool *out)
Finds a bool-like 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 bsonExtractField(const BSONObj &object, const StringData &fieldName, BSONElement *outElement)
Finds an element named "fieldName" in "object".
Status bsonExtractBooleanFieldWithDefault(const BSONObj &object, const StringData &fieldName, bool defaultValue, 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".
Status bsonExtractStringFieldWithDefault(const BSONObj &object, const StringData &fieldName, const StringData &defaultValue, std::string *out)
Finds a string element named "fieldName" in "object".
Status bsonExtractIntegerField(const BSONObj &object, const StringData &fieldName, long long *out)
Finds an element named "fieldName" in "object" that represents an integral value.
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".
BSONType
the complete list of valid BSON types see also bsonspec.org
Definition bsontypes.h:38
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.