MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
mongo Namespace Reference

Utility functions for parsing numbers from strings. More...

Namespaces

namespace  client
 the MongoDB C++ driver namespace
 

Classes

class  _BufBuilder
 
class  AbstractMessagingPort
 
class  AssertionException
 
class  AtomicIntrinsics
 Instantiation of AtomicIntrinsics<> for all word types T. More...
 
class  AtomicIntrinsics< T, typename boost::enable_if_c< sizeof(T)==sizeof(LONG)>::type >
 Instantiation of AtomicIntrinsics<> for 32-bit word sizes (i.e., unsigned). More...
 
class  AtomicIntrinsics< T, typename boost::enable_if_c< sizeof(T)==sizeof(LONGLONG)>::type >
 Instantiation of AtomicIntrinsics<> for 64-bit word sizes. More...
 
class  AtomicWord
 Implementation of the AtomicWord interface in terms of the C++11 Atomics. More...
 
class  BackgroundJob
 Background thread dispatching. More...
 
class  Backoff
 
struct  BSONArray
 
class  BSONArrayBuilder
 
class  BSONArrayIteratorSorted
 Provides iteration of a BSONArray's BSONElements in numeric field order. More...
 
struct  BSONBinData
 
struct  BSONCode
 
struct  BSONCodeWScope
 
struct  BSONDBRef
 
class  BSONElement
 BSONElement represents an "element" in a BSONObj. More...
 
struct  BSONElementCmpWithoutField
 
class  BSONField
 
class  BSONFieldValue
 A BSONField holds the name and the type intended for a given BSON element. More...
 
class  BSONIteratorSorted
 Base class implementing ordered iteration through BSONElements. More...
 
class  BSONObj
 C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representation. More...
 
class  BSONObjBuilder
 Utility for creating a BSONObj. More...
 
class  BSONObjBuilderValueStream
 
class  BSONObjCmp
 
class  BSONObjIterator
 iterator for a BSONObj More...
 
class  BSONObjIteratorSorted
 Provides iteration of a BSONObj's BSONElements in lexical field order. More...
 
struct  BSONRegEx
 
class  BSONSizeTracker
 used in conjuction with BSONObjBuilder, allows for proper buffer size to prevent crazy memory usage More...
 
struct  BSONSymbol
 
class  BulkOperationBuilder
 Class for constructing and executing bulk operations against MongoDB via a fluent API. More...
 
class  BulkUpdateBuilder
 Class for constructing bulk write operations which have an applied filter. More...
 
class  BulkUpsertBuilder
 Class for constructing bulk write operations which have an applied filter and are to be performed as an upsert. More...
 
class  CommandWriter
 
class  ConnectException
 
class  ConnectionCache
 
class  ConnectionString
 ConnectionString can parse MongoDB URIs with the following format: More...
 
class  ConstDataCursor
 
class  ConstDataView
 
class  CyrusSaslClientSession
 Implementation of the client side of a SASL authentication conversation. More...
 
class  DataCursor
 
class  DataView
 
struct  Date_t
 
struct  DateNowLabeler
 
class  DBClientBase
 abstract class that implements the core db operations More...
 
class  DBClientConnection
 A basic connection to the database. More...
 
class  DBClientCursor
 Queries return a cursor object. More...
 
class  DBClientCursorBatchIterator
 iterate over objects in current batch only - will not cause a network call More...
 
class  DBClientCursorInterface
 for mock purposes only – do not create variants of DBClientCursor, nor hang code here More...
 
class  DBClientCursorShim
 DBClientCursorShim provides an abstract interface for providing polymorphic cursors. More...
 
class  DBClientCursorShimArray
 DBClientCursorShimArray implements the shim interface over an array of bson obj's. More...
 
class  DBClientCursorShimCursorID
 DBClientCursorShimCursorID implements the shim interface over a cursor reply document, rather than the traditional OP_REPLY. More...
 
class  DBClientCursorShimTransform
 DBClientCursorShimTransform implements the shim interface over a cursor reply document by allowing a transformation to be applied. More...
 
class  DBClientInterface
 The interface that any db connection should implement. More...
 
class  DBClientMockCursor
 
class  DBClientReplicaSet
 Use this class to connect to a replica set of servers. More...
 
class  DBClientWithCommands
 DB "commands" Basically just invocations of connection. More...
 
class  DBClientWriter
 
class  DBConnector
 interface that handles communication with the db More...
 
class  DBException
 Most mongo exceptions inherit from this; this is commonly caught in most threads. More...
 
class  DbMessage
 
struct  DbResponse
 A response to a DbMessage. More...
 
class  DeleteWriteOperation
 
class  EmbeddedBuilder
 
class  EncodedValueStorage
 
class  ErrorMsg
 helper class that builds error strings. More...
 
struct  ExceptionInfo
 
class  FailPoint
 A simple thread-safe fail point implementation that can be activated and deactivated, as well as embed temporary data into it. More...
 
class  FailPointRegistry
 Class for storing FailPoint instances. More...
 
struct  GENOIDLabeler
 
class  GlobalInitializerRegisterer
 Type representing the act of registering a process-global intialization function. More...
 
class  GridFile
 wrapper for a file stored in the Mongo database More...
 
class  GridFileBuilder
 class which allow to build GridFiles in a stream fashion way More...
 
class  GridFS
 GridFS is for storing large file-style objects in MongoDB. More...
 
class  GridFSChunk
 
struct  HostAndPort
 Name of a process on the network. More...
 
class  IndexSpec
 
class  Initializer
 Class representing an initialization process. More...
 
class  InitializerContext
 Context of an initialization process. More...
 
class  InitializerDependencyGraph
 Representation of a dependency graph of "initialization operations.". More...
 
class  InsertWriteOperation
 
class  JParse
 Parser class. More...
 
class  Labeler
 
class  LexNumCmp
 Functor for combining lexical and numeric comparisons. More...
 
struct  MaxKeyLabeler
 
class  Message
 
class  MessagingPort
 
struct  MinKeyLabeler
 
class  MsgAssertionException
 
struct  NamespaceDBEquals
 
struct  NamespaceDBHash
 
class  NamespaceString
 
class  NativeSaslClientSession
 Implementation of the client side of a SASL authentication conversation using the native SASL implementation. More...
 
class  Notification
 
class  NotifyAll
 establishes a synchronization point between threads. More...
 
struct  NullLabeler
 
class  ObjScopeGuardImpl0
 
class  ObjScopeGuardImpl1
 
class  ObjScopeGuardImpl2
 
class  OID
 Object ID type. More...
 
class  OperationException
 General runtime exception generated by the MongoDB client driver. More...
 
class  Ordering
 A precomputation of a BSON index or sort key pattern. More...
 
class  OwnedPointerVector
 An std::vector wrapper that deletes pointers within a vector on destruction. More...
 
class  PseudoRandom
 Uses http://en.wikipedia.org/wiki/Xorshift. More...
 
class  Query
 Represents a Mongo query expression. More...
 
class  QueryMessage
 
class  QuerySpec
 Represents a full query description, including all options required for the query to be passed on to other hosts. More...
 
struct  ReadPreferenceSetting
 
class  RefToValue
 Transports a reference as a value Serves to implement the Colvin/Gibbons trick for SmartPtr/ScopeGuard. More...
 
class  ReplicaSetMonitor
 Holds state about a replica set and provides a means to refresh the local view. More...
 
class  SaslClientConversation
 Abstract class for implementing the clent-side of a SASL mechanism conversation. More...
 
class  SaslClientSession
 Base class for the client side of a SASL authentication conversation. More...
 
class  SaslPLAINClientConversation
 Client side authentication session for SASL PLAIN. More...
 
class  SaslSCRAMSHA1ClientConversation
 Client side authentication session for SASL PLAIN. More...
 
class  ScopedFailPoint
 Helper class for making sure that FailPoint::shouldFailCloseBlock is called when FailPoint::shouldFailOpenBlock was called. More...
 
class  ScopeGuardImpl0
 
class  ScopeGuardImpl1
 
class  ScopeGuardImpl2
 
class  ScopeGuardImpl3
 
class  ScopeGuardImplBase
 ScopeGuard. More...
 
class  SecureRandom
 More secure random numbers Suitable for nonce/crypto Slower than PseudoRandom, so only use when really need. More...
 
class  SharedBuffer
 
struct  SockAddr
 wrapped around os representation of network address More...
 
class  Socket
 thin wrapped around file descriptor and system calls todo: ssl More...
 
class  SocketException
 thrown by Socket and SockAddr More...
 
class  StackAllocator
 
class  StackBufBuilder
 The StackBufBuilder builds smaller datasets on the stack instead of using malloc. More...
 
class  Status
 Status represents an error state or the absence thereof. More...
 
class  StatusWith
 
class  StringBuilderImpl
 std::stringstream deals with locale so this is a lot faster than std::stringstream for UTF8 More...
 
class  StringData
 A StringData object wraps a 'const string&' or a 'const char*' without copying its contents. More...
 
class  StringMap
 
struct  StringMapDefaultConvertor
 
struct  StringMapDefaultConvertorOther
 
struct  StringMapDefaultEqual
 
class  StringSplitter
 
class  TagSet
 A simple object for representing the list of tags requested by a $readPreference. More...
 
class  ThreadLocalValue
 
class  Timer
 Time tracking object. More...
 
class  Timestamp_t
 
class  TrivialAllocator
 
struct  TSP
 
struct  UndefinedLabeler
 
class  UnorderedFastKeyTable
 
struct  UnorderedFastKeyTable_LS_C
 
class  UpdateWriteOperation
 
class  UserException
 
class  WireProtocolWriter
 
class  WriteConcern
 Class to encapsulate client side "Write Concern" concept. More...
 
class  WriteOperation
 Represents a single server side write operation and encapsulates the process for encoding the operation into either a wire protocol request message or a command. More...
 
class  WriteOperationBase
 
class  WriteResult
 Class representing the result of a write operations sent to the server. More...
 
struct  ZeroInitTag_t
 

Typedefs

typedef stdx::function< Status(InitializerContext *)> InitializerFunction
 An InitializerFunction implements the behavior of an initializer operation.
 
typedef const ScopeGuardImplBaseScopeGuard
 See Andrei's and Petru Marginean's CUJ article http://www.cuj.com/documents/s=8000/cujcexp1812alexandr/alexandr.htm.
 

Enumerations

enum  BSONType {
  MinKey = -1 , EOO = 0 , NumberDouble = 1 , String = 2 ,
  Object = 3 , Array = 4 , BinData = 5 , Undefined = 6 ,
  jstOID = 7 , Bool = 8 , Date = 9 , jstNULL = 10 ,
  RegEx = 11 , DBRef = 12 , Code = 13 , Symbol = 14 ,
  CodeWScope = 15 , NumberInt = 16 , Timestamp = 17 , NumberLong = 18 ,
  JSTypeMax = 18 , MaxKey = 127
}
 the complete list of valid BSON types see also bsonspec.org More...
 
enum  JsonStringFormat { Strict , TenGen , JS }
 Formatting mode for generating JSON from BSON. More...
 
enum  UpdateOptions { UpdateOption_Upsert = 1 << 0 , UpdateOption_Multi = 1 << 1 , UpdateOption_Broadcast = 1 << 2 , UpdateOption_BypassDocumentValidation = 1 << 3 }
 
enum  RemoveOptions { RemoveOption_JustOne = 1 << 0 , RemoveOption_Broadcast = 1 << 1 }
 
enum  InsertOptions { InsertOption_ContinueOnError = 1 << 0 , InsertOption_BypassDocumentValidation = 1 << 1 }
 need to put in DbMesssage::ReservedOptions as well More...
 

Functions

int compareInts (int lhs, int rhs)
 These functions compare numbers using the same rules as BSON.
 
InitializergetGlobalInitializer ()
 Get the process-global initializer object.
 
Status runGlobalInitializers (const InitializerContext::ArgumentVector &args, const InitializerContext::EnvironmentMap &env)
 Run the global initializers.
 
void runGlobalInitializersOrDie (int argc, const char *const *argv, const char *const *envp)
 Same as runGlobalInitializers(), except prints a brief message to std::cerr and terminates the process on failure.
 
std::vector< std::string > _makeStringVector (int ignored,...)
 Create a vector of strings from varargs of C-style strings.
 
template<typename NumberType >
MONGO_CLIENT_API Status MONGO_CLIENT_FUNC parseNumberFromStringWithBase (const StringData &stringValue, int base, NumberType *result)
 Parses a number out of a StringData.
 
MONGO_CLIENT_API Status MONGO_CLIENT_FUNC validateBSON (const char *buf, uint64_t maxLength)
 
const char * typeName (BSONType type)
 returns the name of the argument's type
 
int canonicalizeBSONType (BSONType type)
 Returns a number for where a given type falls in the sort order.
 
Status bsonExtractField (const BSONObj &object, const StringData &fieldName, BSONElement *outElement)
 Finds an 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 bsonExtractBooleanField (const BSONObj &object, const StringData &fieldName, bool *out)
 Finds a bool-like 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 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 bsonExtractBooleanFieldWithDefault (const BSONObj &object, const StringData &fieldName, bool defaultValue, bool *out)
 Finds a bool-like element named "fieldName" in "object".
 
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 bsonExtractStringFieldWithDefault (const BSONObj &object, const StringData &fieldName, const StringData &defaultValue, std::string *out)
 Finds a string 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.
 
MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC nsGetDB (const std::string &ns)
 
MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC nsGetCollection (const std::string &ns)
 
MONGO_CLIENT_API bool MONGO_CLIENT_FUNC serverAlive (const std::string &uri)
 pings server to check if it's up
 
MONGO_CLIENT_API Status (MONGO_CLIENT_FUNC *saslClientAuthenticate)(DBClientWithCommands *client
 Attempts to authenticate "client" using the SASL protocol.
 
MONGO_CLIENT_API Status MONGO_CLIENT_FUNC saslExtractPayload (const BSONObj &cmdObj, std::string *payload, BSONType *type)
 Extracts the payload field from "cmdObj", and store it into "*payload".
 
void replyToQuery (int queryResultFlags, Message &response, const BSONObj &resultObj)
 Helper method for setting up a response object.
 
MONGO_CLIENT_API BSONObj MONGO_CLIENT_FUNC fromjson (const std::string &str)
 Create a BSONObj from a JSON http://www.json.org, http://www.ietf.org/rfc/rfc4627.txt string.
 
MONGO_CLIENT_API BSONObj MONGO_CLIENT_FUNC fromjson (const char *str, int *len=NULL)
 
MONGO_CLIENT_API bool isArray (const StringData &str)
 Tests whether the JSON string is an Array.
 
MONGO_CLIENT_API std::string tojson (const BSONArray &arr, JsonStringFormat format=Strict, bool pretty=false)
 Convert a BSONArray to a JSON string.
 
MONGO_CLIENT_API std::string tojson (const BSONObj &obj, JsonStringFormat format=Strict, bool pretty=false)
 Convert a BSONObj to a JSON string.
 
int nsDBHash (const std::string &ns)
 NamespaceDBHash and NamespaceDBEquals allow you to do something like unordered_map<string,int,NamespaceDBHash,NamespaceDBEquals> and use the full namespace for the string but comparisons are done only on the db piece.
 
bool legalClientSystemNS (const StringData &ns, bool write)
 
bool nsIsFull (const StringData &ns)
 foo = false foo.
 
bool nsIsDbOnly (const StringData &ns)
 foo = true foo.
 
MONGO_CLIENT_API MONGO_COMPILER_NORETURN void MONGO_CLIENT_FUNC uasserted (int msgid, const char *msg)
 a "user assertion".
 
MONGO_CLIENT_API MONGO_COMPILER_NORETURN void MONGO_CLIENT_FUNC msgassertedNoTrace (int msgid, const char *msg)
 msgassert and massert are for errors that are internal but have a well defined error text std::string.
 
MONGO_CLIENT_API void MONGO_CLIENT_FUNC fassert (int msgid, bool testOK)
 aborts on condition failure
 
FailPointRegistrygetGlobalFailPointRegistry ()
 
std::string errnoWithPrefix (const char *prefix)
 output the error # and error message with prefix.
 
void logContext (const char *msg=NULL)
 Write the optional "msg".
 
std::string getHostName ()
 this is not cache and does a syscall
 
std::string createPasswordDigest (const StringData &username, const StringData &clearTextPassword)
 Hashes the password so that it can be stored in a user object or used for MONGODB-CR authentication.
 
template<class T >
RefToValue< T > ByRef (T &t)
 RefToValue creator.
 
std::string constructUtf8WindowsCommandLine (const std::vector< std::string > &argv)
 Construct a Windows command line string, UTF-8 encoded, from a vector of UTF-8 arguments, "argv".
 
MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC timeToISOString (time_t time)
 Formats "time" according to the ISO 8601 extended form standard, including date, and time, in the UTC timezone.
 
MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC dateToISOStringUTC (Date_t date)
 Formats "date" according to the ISO 8601 extended form standard, including date, and time with milliseconds decimal component, in the UTC timezone.
 
MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC dateToISOStringLocal (Date_t date)
 Formats "date" according to the ISO 8601 extended form standard, including date, and time with milliseconds decimal component, in the local timezone.
 
MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC dateToCtimeString (Date_t date)
 Formats "date" in fixed width in the local time zone.
 
MONGO_CLIENT_API StatusWith< Date_t > MONGO_CLIENT_FUNC dateFromISOString (const StringData &dateString)
 Parses a Date_t from an ISO 8601 string representation.
 
MONGO_CLIENT_API void MONGO_CLIENT_FUNC outputDateAsISOStringUTC (std::ostream &os, Date_t date)
 Like dateToISOStringUTC, except outputs to a std::ostream.
 
MONGO_CLIENT_API void MONGO_CLIENT_FUNC outputDateAsISOStringLocal (std::ostream &os, Date_t date)
 Like dateToISOStringLocal, except outputs to a std::ostream.
 
MONGO_CLIENT_API void MONGO_CLIENT_FUNC outputDateAsCtime (std::ostream &os, Date_t date)
 Like dateToCtimeString, except outputs to a std::ostream.
 
MONGO_CLIENT_API Date_t MONGO_CLIENT_FUNC jsTime ()
 Date_t is milliseconds since epoch.
 
unsigned curTimeMicros ()
 warning this will wrap
 

Variables

MONGO_CLIENT_API const char *const saslStartCommandName
 String name of the saslStart command.
 
MONGO_CLIENT_API const char *const saslContinueCommandName
 String name of the saslContinue command.
 
MONGO_CLIENT_API const char *const saslCommandAutoAuthorizeFieldName
 Name of the saslStart parameter indicating that the server should automatically grant the connection all privileges associated with the user after successful authentication.
 
MONGO_CLIENT_API const char *const saslCommandCodeFieldName
 Name of the field contain the status code in responses from the server.
 
MONGO_CLIENT_API const char *const saslCommandConversationIdFieldName
 Name of the field containing the conversation identifier in server respones and saslContinue commands.
 
MONGO_CLIENT_API const char *const saslCommandDoneFieldName
 Name of the field that indicates whether or not the server believes authentication has completed successfully.
 
MONGO_CLIENT_API const char *const saslCommandErrmsgFieldName
 Field in which to store error messages associated with non-success return codes.
 
MONGO_CLIENT_API const char *const saslCommandMechanismFieldName
 Name of parameter to saslStart command indiciating the client's desired sasl mechanism.
 
MONGO_CLIENT_API const char *const saslCommandMechanismListFieldName
 In the event that saslStart supplies an unsupported mechanism, the server responds with a field by this name, with a list of supported mechanisms.
 
MONGO_CLIENT_API const char *const saslCommandPasswordFieldName
 Field containing password information for saslClientAuthenticate().
 
MONGO_CLIENT_API const char *const saslCommandPayloadFieldName
 Field containing sasl payloads passed to and from the server.
 
MONGO_CLIENT_API const char *const saslCommandUserFieldName
 Field containing the string identifier of the user to authenticate in saslClientAuthenticate().
 
MONGO_CLIENT_API const char *const saslCommandUserDBFieldName
 Field containing the string identifier of the database containing credential information, or "$external" if the credential information is stored outside of the mongo cluster.
 
MONGO_CLIENT_API const char *const saslCommandServiceHostnameFieldName
 Field overriding the FQDN of the hostname hosting the mongodb srevice in saslClientAuthenticate().
 
MONGO_CLIENT_API const char *const saslCommandServiceNameFieldName
 Field overriding the name of the mongodb service saslClientAuthenticate().
 
MONGO_CLIENT_API const char *const saslDefaultDBName
 Default database against which sasl authentication commands should run.
 
MONGO_CLIENT_API const char *const saslDefaultServiceName
 Default sasl service name, "mongodb".
 
const size_t MaxMessageSizeBytes = 48 * 1000 * 1000
 Maximum accepted message size on the wire protocol.
 

Detailed Description

Utility functions for parsing numbers from strings.

Copyright (C) 2014 MongoDB Inc.

Copyright 2012 10gen Inc.

Should NOT be included by other header files.

Include "mongo/platform/cstdint.h" to get the C++11 cstdint types in namespace mongo.

Implementation of the AtomicIntrinsics<T>::* operations for Windows systems.

Implementation of the AtomicIntrinsics<T>::* operations for systems on any architecture using a GCC 4.1+ compatible compiler toolchain.

Implementation of the AtomicIntrinsics<T>::* operations for IA-32 and AMD64 systems using a GCC-compatible compiler toolchain.

Implementation of the AtomicIntrinsics<T>::* operations for systems on any architecture using a new enough GCC-compatible compiler toolchain.

replica set member

Copyright (C) 2014 10gen Inc.

This is an internal header.

the main MongoDB namespace

This should only be included by replica_set_monitor.cpp and replica_set_monitor_test.cpp. This should never be included by any header.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Include only in source files.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Typedef Documentation

◆ InitializerFunction

An InitializerFunction implements the behavior of an initializer operation.

On successful execution, an InitializerFunction returns Status::OK(). It may inspect and mutate the supplied InitializerContext.

◆ ScopeGuard

See Andrei's and Petru Marginean's CUJ article http://www.cuj.com/documents/s=8000/cujcexp1812alexandr/alexandr.htm.

Changes to the original code by Joshua Lehrer: http://www.lehrerfamily.com/scopeguard.html

Enumeration Type Documentation

◆ BSONType

the complete list of valid BSON types see also bsonspec.org

Enumerator
MinKey 

smaller than all other types

EOO 

end of object

NumberDouble 

double precision floating point value

String 

character string, stored in utf8

Object 

an embedded object

Array 

an embedded array

BinData 

binary data

Undefined 

Undefined type.

jstOID 

ObjectId.

Bool 

boolean type

Date 

date type

jstNULL 

null type

RegEx 

regular expression, a pattern with options

DBRef 

deprecated / will be redesigned

Code 

deprecated / use CodeWScope

Symbol 

a programming language (e.g., Python) symbol

CodeWScope 

javascript code that can execute on the database server, with SavedContext

NumberInt 

32 bit signed integer

Timestamp 

Updated to a Date with value next OpTime on insert.

NumberLong 

64 bit integer

JSTypeMax 

max type that is not MaxKey

MaxKey 

larger than all other types

◆ InsertOptions

need to put in DbMesssage::ReservedOptions as well

Enumerator
InsertOption_ContinueOnError 

With muli-insert keep processing inserts if one fails.

InsertOption_BypassDocumentValidation 

Disables document validation for this operation.

◆ JsonStringFormat

Formatting mode for generating JSON from BSON.

See http://dochub.mongodb.org/core/mongodbextendedjson for details.

Enumerator
Strict 

strict RFC format

TenGen 

10gen format, which is close to JS format.

This form is understandable by javascript running inside the Mongo server via eval()

JS 

Javascript JSON compatible.

◆ RemoveOptions

Enumerator
RemoveOption_JustOne 

only delete one option

RemoveOption_Broadcast 

flag from mongo saying this update went everywhere

◆ UpdateOptions

Enumerator
UpdateOption_Upsert 

Upsert - that is, insert the item if no matching item is found.

UpdateOption_Multi 

Update multiple documents (if multiple documents match query expression).

(Default is update a single document and stop.)

UpdateOption_Broadcast 

flag from mongo saying this update went everywhere

UpdateOption_BypassDocumentValidation 

Disables document validation for this operation.

Function Documentation

◆ _makeStringVector()

std::vector< std::string > mongo::_makeStringVector ( int  ignored,
  ... 
)

Create a vector of strings from varargs of C-style strings.

WARNING: Only intended for use by MONGO_MAKE_STRING_VECTOR macro, defined above. Aborts ungracefully if you misuse it, so stick to the macro.

The first parameter is ignored in all circumstances. The subsequent parameters must be const char* C-style strings, or NULL. Of these parameters, at least one must be NULL. Parameters at and beyond the NULL are not inserted. Typically, the NULL will be the last parameter. The MONGO_MAKE_STRING_VECTOR macro enforces this.

Returns a vector of std::strings.

◆ bsonExtractBooleanField()

Status mongo::bsonExtractBooleanField ( const BSONObj object,
const StringData fieldName,
bool *  out 
)

Finds a bool-like element named "fieldName" in "object".

Returns Status::OK() and sets *out to the found element's boolean value on success. Returns ErrorCodes::NoSuchKey if there are no matches for "fieldName", and ErrorCodes::TypeMismatch if the type of the matching element is not Bool or a number type. For return values other than Status::OK(), the resulting value of "*out" is undefined.

◆ bsonExtractBooleanFieldWithDefault()

Status mongo::bsonExtractBooleanFieldWithDefault ( const BSONObj object,
const StringData fieldName,
bool  defaultValue,
bool *  out 
)

Finds a bool-like element named "fieldName" in "object".

If a field named "fieldName" is present, and is either a number or boolean type, stores the truth value of the field into "*out". If no field named "fieldName" is present, sets "*out" to "defaultValue". In these cases, returns Status::OK().

If "fieldName" is present more than once, behavior is undefined. If the found field is not a boolean or number, returns ErrorCodes::TypeMismatch.

◆ bsonExtractField()

Status mongo::bsonExtractField ( const BSONObj object,
const StringData fieldName,
BSONElement outElement 
)

Finds an element named "fieldName" in "object".

Returns Status::OK() and sets "*outElement" to the found element on success. Returns ErrorCodes::NoSuchKey if there are no matches.

◆ bsonExtractIntegerField()

Status mongo::bsonExtractIntegerField ( const BSONObj object,
const StringData fieldName,
long long *  out 
)

Finds an element named "fieldName" in "object" that represents an integral value.

Returns Status::OK() and sets *out to the element's 64-bit integer value representation on success. Returns ErrorCodes::NoSuchKey if there are no matches for "fieldName". Returns ErrorCodes::TypeMismatch if the value of the matching element is not of a numeric type. Returns ErrorCodes::BadValue if the value does not have an exact 64-bit integer representation. For return values other than Status::OK(), the resulting value of "*out" is undefined.

◆ bsonExtractIntegerFieldWithDefault()

Status mongo::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.

If a field named "fieldName" is present and is a value of numeric type with an exact 64-bit integer representation, returns that representation in *out and returns Status::OK(). If there is no field named "fieldName", stores defaultValue into *out and returns Status::OK(). If the field is found, but has non-numeric type, returns ErrorCodes::TypeMismatch. If the value has numeric type, but cannot be represented as a 64-bit integer, returns ErrorCodes::BadValue.

◆ bsonExtractOIDField()

Status mongo::bsonExtractOIDField ( const BSONObj object,
const StringData fieldName,
OID out 
)

Finds an OID-typed element named "fieldName" in "object" and stores its value in "out".

Returns Status::OK() and sets *out to the found element's OID value on success. Returns ErrorCodes::NoSuchKey if there are no matches for "fieldName", and ErrorCodes::TypeMismatch if the type of the matching element is not OID. For return values other than Status::OK(), the resulting value of "*out" is undefined.

◆ bsonExtractOIDFieldWithDefault()

Status mongo::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.

Returns Status::OK() and sets *out to the found element's OID value on success. If no field named "fieldName" is present, *out is set to "defaultValue" and Status::OK() is returned. Returns ErrorCodes::TypeMismatch if the type of the matching element is not OID. For return values other than Status::OK(), the resulting value of *out is undefined.

◆ bsonExtractStringField()

Status mongo::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".

Returns Status::OK() and sets *out to the found element's string value on success. Returns ErrorCodes::NoSuchKey if there are no matches for "fieldName", and ErrorCodes::TypeMismatch if the type of the matching element is not String. For return values other than Status::OK(), the resulting value of "*out" is undefined.

◆ bsonExtractStringFieldWithDefault()

Status mongo::bsonExtractStringFieldWithDefault ( const BSONObj object,
const StringData fieldName,
const StringData defaultValue,
std::string *  out 
)

Finds a string element named "fieldName" in "object".

If a field named "fieldName" is present, and is a string, stores the value of the field into "*out". If no field named fieldName is present, sets "*out" to "defaultValue". In these cases, returns Status::OK().

If "fieldName" is present more than once, behavior is undefined. If the found field is not a string, returns ErrorCodes::TypeMismatch.

◆ bsonExtractTypedField()

Status mongo::bsonExtractTypedField ( const BSONObj object,
const StringData fieldName,
BSONType  type,
BSONElement outElement 
)

Finds an element named "fieldName" in "object".

Returns Status::OK() and sets *outElement to the found element on success. Returns ErrorCodes::NoSuchKey if there are no matches for "fieldName", and ErrorCodes::TypeMismatch if the type of the matching element is not "type". For return values other than Status::OK(), the resulting value of "*outElement" is undefined.

◆ canonicalizeBSONType()

int mongo::canonicalizeBSONType ( BSONType  type)
inline

Returns a number for where a given type falls in the sort order.

Elements with the same return value should be compared for value equality. The return value is not a BSONType and should not be treated as one. Note: if the order changes, indexes have to be re-built or than can be corruption

◆ compareInts()

int mongo::compareInts ( int  lhs,
int  rhs 
)
inline

These functions compare numbers using the same rules as BSON.

Care is taken to always give numerically correct results when comparing different types. Returns are always -1, 0, or 1 to ensure it is safe to negate the result to invert the direction of the comparison.

◆ constructUtf8WindowsCommandLine()

std::string mongo::constructUtf8WindowsCommandLine ( const std::vector< std::string > &  argv)

Construct a Windows command line string, UTF-8 encoded, from a vector of UTF-8 arguments, "argv".

See "Parsing C++ Command-Line Arguments (C++)" http://msdn.microsoft.com/en-us/library/windows/desktop/17w5ykft(v=vs.85).aspx

◆ dateFromISOString()

MONGO_CLIENT_API StatusWith< Date_t > MONGO_CLIENT_FUNC mongo::dateFromISOString ( const StringData dateString)

Parses a Date_t from an ISO 8601 string representation.

Sample formats: "2013-07-23T18:42:14.072-05:00" "2013-07-23T18:42:14.072Z"

Local times are currently not supported.

◆ dateToCtimeString()

MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC mongo::dateToCtimeString ( Date_t  date)

Formats "date" in fixed width in the local time zone.

Sample format: "Wed Oct 31 13:34:47.996"

◆ dateToISOStringLocal()

MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC mongo::dateToISOStringLocal ( Date_t  date)

Formats "date" according to the ISO 8601 extended form standard, including date, and time with milliseconds decimal component, in the local timezone.

Sample format: "2013-07-23T18:42:14.072-05:00"

◆ dateToISOStringUTC()

MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC mongo::dateToISOStringUTC ( Date_t  date)

Formats "date" according to the ISO 8601 extended form standard, including date, and time with milliseconds decimal component, in the UTC timezone.

Sample format: "2013-07-23T18:42:14.072Z"

◆ errnoWithPrefix()

std::string mongo::errnoWithPrefix ( const char *  prefix)

output the error # and error message with prefix.

handy for use as parm in uassert/massert.

◆ fromjson() [1/2]

MONGO_CLIENT_API BSONObj MONGO_CLIENT_FUNC mongo::fromjson ( const char *  str,
int *  len = NULL 
)
Parameters
lenwill be size of JSON object in text chars.

◆ fromjson() [2/2]

MONGO_CLIENT_API BSONObj MONGO_CLIENT_FUNC mongo::fromjson ( const std::string &  str)

Create a BSONObj from a JSON http://www.json.org, http://www.ietf.org/rfc/rfc4627.txt string.

In addition to the JSON extensions extensions described here http://dochub.mongodb.org/core/mongodbextendedjson, this function accepts unquoted field names and allows single quotes to optionally be used when specifying field names and string values instead of double quotes. JSON unicode escape sequences (of the form \uXXXX) are converted to utf8.

Exceptions
MsgAssertionExceptionif parsing fails. The message included with this assertion includes the character offset where parsing failed.

◆ getGlobalFailPointRegistry()

FailPointRegistry * mongo::getGlobalFailPointRegistry ( )
Returns
the global fail point registry.

◆ getGlobalInitializer()

Initializer & mongo::getGlobalInitializer ( )

Get the process-global initializer object.

See mongo/base/initializer.h and mongo/base/init.h for information about process initialization in mongo applications.

◆ isArray()

MONGO_CLIENT_API bool mongo::isArray ( const StringData str)

Tests whether the JSON string is an Array.

Useful for assigning the result of fromjson to the right object type. Either: BSONObj BSONArray

Example: Using the method to select the proper type.

If this method returns true, the user could store the result of fromjson inside a BSONArray, rather than a BSONObj, in order to have it print as an array when passed to tojson.

Parameters
objThe JSON string to test.

◆ legalClientSystemNS()

bool mongo::legalClientSystemNS ( const StringData ns,
bool  write 
)
Returns
true if a client can modify this namespace even though it is under ".system." For example <dbname>.system.users is ok for regular clients to update.
Parameters
writeused when .system.js

◆ msgassertedNoTrace()

MONGO_CLIENT_API MONGO_COMPILER_NORETURN void MONGO_CLIENT_FUNC mongo::msgassertedNoTrace ( int  msgid,
const char *  msg 
)

msgassert and massert are for errors that are internal but have a well defined error text std::string.

a stack trace is logged.

◆ nsDBHash()

int mongo::nsDBHash ( const std::string &  ns)
inline

NamespaceDBHash and NamespaceDBEquals allow you to do something like unordered_map<string,int,NamespaceDBHash,NamespaceDBEquals> and use the full namespace for the string but comparisons are done only on the db piece.

this can change, do not store on disk

◆ nsGetCollection()

MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC mongo::nsGetCollection ( const std::string &  ns)
Returns
the collection name portion of an ns string

◆ nsGetDB()

MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC mongo::nsGetDB ( const std::string &  ns)
Returns
the database name portion of an ns string

◆ nsIsDbOnly()

bool mongo::nsIsDbOnly ( const StringData ns)
inline

foo = true foo.

= false foo.a = false

◆ nsIsFull()

bool mongo::nsIsFull ( const StringData ns)
inline

foo = false foo.

= false foo.a = true

◆ parseNumberFromStringWithBase()

template<typename NumberType >
MONGO_CLIENT_API Status MONGO_CLIENT_FUNC mongo::parseNumberFromStringWithBase ( const StringData stringValue,
int  base,
NumberType *  result 
)

Parses a number out of a StringData.

Parses "stringValue", interpreting it as a number of the given "base". On success, stores the parsed value into "*result" and returns Status::OK().

Valid values for "base" are 2-36, with 0 meaning "choose the base by inspecting the prefix on the number", as in strtol. Returns Status::BadValue if an illegal value is supplied for "base".

The entirety of the string must consist of digits in the given base, except optionally the first character may be "+" or "-", and hexadecimal numbers may begin "0x". Same as strtol, without the property of stripping whitespace at the beginning, and fails to parse if there are non-digit characters at the end of the string.

See parse_number.cpp for the available instantiations, and add any new instantiations there.

◆ replyToQuery()

void mongo::replyToQuery ( int  queryResultFlags,
Message response,
const BSONObj resultObj 
)

Helper method for setting up a response object.

Parameters
queryResultFlagsThe flags to set to the response object.
responseThe object to be used for building the response. The internal buffer of this object will contain the raw data from resultObj after a successful call.
resultObjThe bson object that contains the reply data.

◆ runGlobalInitializers()

Status mongo::runGlobalInitializers ( const InitializerContext::ArgumentVector &  args,
const InitializerContext::EnvironmentMap &  env 
)

Run the global initializers.

It's a programming error for this to fail, but if it does it will return a status other than Status::OK.

This means that the few initializers that might want to terminate the program by failing should probably arrange to terminate the process themselves.

◆ saslExtractPayload()

MONGO_CLIENT_API Status MONGO_CLIENT_FUNC mongo::saslExtractPayload ( const BSONObj cmdObj,
std::string *  payload,
BSONType type 
)

Extracts the payload field from "cmdObj", and store it into "*payload".

Sets "*type" to the BSONType of the payload field in cmdObj.

If the type of the payload field is String, the contents base64 decodes and stores into "*payload". If the type is BinData, the contents are stored directly into "*payload". In all other cases, returns

◆ Status()

MONGO_CLIENT_API mongo::Status ( MONGO_CLIENT_FUNC *  saslClientAuthenticate)

Attempts to authenticate "client" using the SASL protocol.

Do not use directly in client code. Use the DBClientWithCommands::auth(const BSONObj&) method, instead.

Test against NULL for availability. Client driver must be compiled with SASL support and client application must have successfully executed mongo::runGlobalInitializersOrDie() or its ilk to make this functionality available.

The "saslParameters" BSONObj should be initialized with zero or more of the fields below. Which fields are required depends on the mechanism. Consult the relevant IETF standards.

"mechanism": The string name of the sasl mechanism to use.  Mandatory.
"autoAuthorize": Truthy values tell the server to automatically acquire privileges on
    all resources after successful authentication, which is the default.  Falsey values
    instruct the server to await separate privilege-acquisition commands.
"user": The string name of the user to authenticate.
"db": The database target of the auth command, which identifies the location
    of the credential information for the user.  May be "$external" if credential
    information is stored outside of the mongo cluster.
"pwd": The password.
"serviceName": The GSSAPI service name to use.  Defaults to "mongodb".
"serviceHostname": The GSSAPI hostname to use.  Defaults to the name of the remote host.

Other fields in saslParameters are silently ignored.

Returns an OK status on success, and ErrorCodes::AuthenticationFailed if authentication is rejected. Other failures, all of which are tantamount to authentication failure, may also be returned.

◆ timeToISOString()

MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC mongo::timeToISOString ( time_t  time)

Formats "time" according to the ISO 8601 extended form standard, including date, and time, in the UTC timezone.

Sample format: "2013-07-23T18:42:14Z"

◆ tojson() [1/2]

MONGO_CLIENT_API std::string mongo::tojson ( const BSONArray arr,
JsonStringFormat  format = Strict,
bool  pretty = false 
)

Convert a BSONArray to a JSON string.

Parameters
arrThe BSON Array.
formatThe JSON format (JS, TenGen, Strict).
prettyEnables pretty output.

◆ tojson() [2/2]

MONGO_CLIENT_API std::string mongo::tojson ( const BSONObj obj,
JsonStringFormat  format = Strict,
bool  pretty = false 
)

Convert a BSONObj to a JSON string.

Parameters
objThe BSON Object.
formatThe JSON format (JS, TenGen, Strict).
prettyEnables pretty output.

◆ uasserted()

MONGO_CLIENT_API MONGO_COMPILER_NORETURN void MONGO_CLIENT_FUNC mongo::uasserted ( int  msgid,
const char *  msg 
)

a "user assertion".

throws UserAssertion. logs. typically used for errors that a user could cause, such as duplicate key, disk full, etc.

◆ validateBSON()

MONGO_CLIENT_API Status MONGO_CLIENT_FUNC mongo::validateBSON ( const char *  buf,
uint64_t  maxLength 
)
Parameters
buf- bson data
maxLength- maxLength of buffer this is NOT the bson size, but how far we know the buffer is valid