mongo Namespace Reference

distribuetd locking mechanism More...


struct  PoolForHost
class  DBConnectionHook
class  DBConnectionPool
 Database connection pool. More...
class  ScopedDbConnection
 Use to get a connection from the pool. More...
class  ConnectionString
class  Query
 Represents a Mongo query expression. More...
class  DBConnector
 interface that handles communication with the db More...
class  DBClientInterface
 The interface that any db connection should implement. More...
class  DBClientWithCommands
 DB "commands" Basically just invocations of connection. More...
class  DBClientBase
 abstract class that implements the core db operations More...
class  ConnectException
class  DBClientConnection
 A basic connection to the database. More...
class  DBClientPaired
 Use this class to connect to a replica pair of servers. More...
class  DBClientCursor
 Queries return a cursor object. More...
class  DistributedLock
class  dist_lock_try
class  GridFSChunk
class  GridFS
 this is the main entry point into the mongo grid fs More...
class  GridFile
 wrapper for a file stored in the Mongo database More...
class  Model
 Model is a base class for defining objects which are serializable to the Mongo database via the database driver. More...
class  ServerAndQuery
 holder for a server address and a query to run More...
class  ClusteredCursor
 this is a cursor that works over a set of servers can be used in serial/paralellel as controlled by sub classes More...
class  FilteringClientCursor
class  Servers
class  SerialServerClusteredCursor
 runs a query in serial across any number of servers returns all results from 1 server, then the next, etc. More...
class  ParallelSortClusteredCursor
 runs a query in parellel across N servers sots More...
class  Future
 tools for doing asynchronous operations right now uses underlying sync network ops and uses another thread should be changed to use non-blocking io More...
class  SyncClusterConnection
 This is a connection to a cluster of servers that operate as one for super high durability. More...
class  BSONElement
 BSONElement represents an "element" in a BSONObj. More...
struct  BSONElementFieldNameCmp
struct  BSONElementCmpWithoutField
class  BSONObjCmp
class  BSONObjCmpDefaultOrder
struct  GENOIDLabeler
struct  DateNowLabeler
class  Labeler
class  BSONObjBuilderValueStream
class  BSONSizeTracker
 used in conjuction with BSONObjBuilder, allows for proper buffer size to prevent crazy memory usage More...
class  BSONObj
 C++ representation of a "BSON" object -- that is, an extended JSON-style object in a binary representation. More...
struct  BSONArray
class  BSONFieldValue
class  BSONField
class  BSONObjBuilder
 Utility for creating a BSONObj. More...
class  BSONArrayBuilder
class  BSONObjIterator
 iterator for a BSONObj More...
class  BSONObjIteratorSorted
class  OID
 Object ID type. More...
class  Ordering
 A precomputation of a BSON key pattern. More...
struct  AtomicUInt
class  BufBuilder
class  StringBuilder
struct  Date_t


typedef unsigned long long gridfs_offset
typedef map< string, BSONElementBSONMap
typedef set< BSONElement,
typedef set< BSONObj,
typedef set< BSONElement,


enum  QueryOptions {
  QueryOption_CursorTailable = 1 << 1, QueryOption_SlaveOk = 1 << 2, QueryOption_OplogReplay = 1 << 3, QueryOption_NoCursorTimeout = 1 << 4,
  QueryOption_AwaitData = 1 << 5, QueryOption_Exhaust = 1 << 6

the query field 'options' can have these bits set:

enum  UpdateOptions { UpdateOption_Upsert = 1 << 0, UpdateOption_Multi = 1 << 1 }
enum  WriteConcern { W_NONE = 0, W_NORMAL = 1 }

controls how much a clients cares about writes default is NORMAL

enum  FieldCompareResult {
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

enum  BinDataType {
  BinDataGeneral = 0, Function = 1, ByteArrayDeprecated = 2, bdtUUID = 3,
  MD5Type = 5, bdtCustom = 128
enum  JsonStringFormat { Strict, TenGen, JS }

Formatting mode for generating JSON from BSON.



void dbexit (ExitCode returnCode, const char *whyMsg)
bool inShutdown ()
void setupSignals ()
string getDbContext ()
bool haveLocalShardingInfo (const string &ns)
DBClientBasecreateDirectClient ()
void testSort ()
void testDbEval ()
void testPaired ()
void assembleRequest (const string &ns, BSONObj query, int nToReturn, int nToSkip, const BSONObj *fieldsToReturn, int queryOptions, Message &toSend)
bool serverAlive (const string &uri)
 pings server to check if it's up
BSONObj fromjson (const string &str)
 Create a BSONObj from a JSON <> string.
BSONObj fromjson (const char *str, int *len=NULL)
 len will be size of JSON object in text chars.
void assert (bool expr)
void uasserted (unsigned msgid, std::string)
void uassert (unsigned msgid, std::string msg, bool expr)
void msgasserted (int msgid, const char *msg)
void msgasserted (int msgid, const std::string &msg)
void massert (unsigned msgid, std::string msg, bool expr)
unsigned getRandomNumber ()
int compareElementValues (const BSONElement &l, const BSONElement &r)
void nested2dotted (BSONObjBuilder &b, const BSONObj &obj, const string &base="")
BSONObj nested2dotted (const BSONObj &obj)
void dotted2nested (BSONObjBuilder &b, const BSONObj &obj)
BSONObj dotted2nested (const BSONObj &obj)
BSONMap bson2map (const BSONObj &obj)
BSONSortedElements bson2set (const BSONObj &obj)
ostream & operator<< (ostream &s, const BSONObj &o)
ostream & operator<< (ostream &s, const BSONElement &e)
int getGtLtOp (const BSONElement &e)
FieldCompareResult compareDottedFieldNames (const string &l, const string &r)
ostream & operator<< (ostream &s, const OID &o)
void time_t_to_String (time_t t, char *buf)
string time_t_to_String (time_t t=time(0))


CmdLine cmdLine
const char * curNs = "in client mode"
bool dbexitCalled = false
DBConnectionPool pool
mongo::PoolFlushCmd poolFlushCmd
mongo::PoolStats poolStatsCmd
BSONObj getlasterrorcmdobj = fromjson("{getlasterror:1}")
BSONObj getpreverrorcmdobj = fromjson("{getpreverror:1}")
BSONObj getnoncecmdobj = fromjson("{getnonce:1}")
BSONObj ismastercmdobj = fromjson("{\"ismaster\":1}")
BSONObj getprofilingcmdobj = fromjson("{\"profile\":-1}")
string ourHostname
const unsigned DEFAULT_CHUNK_SIZE = 256 * 1024
struct mongo::GENOIDLabeler GENOID
struct mongo::DateNowLabeler DATENOW
Labeler::Label GT
Labeler::Label GTE
Labeler::Label LT
Labeler::Label LTE
Labeler::Label NE
Labeler::Label SIZE
BSONObj maxKey
BSONObj minKey

Detailed Description

distribuetd locking mechanism

Copyright (C) 2008 10gen Inc.

tools for working in parallel/sharded/clustered environment

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <>.

Enumeration Type Documentation

the complete list of valid BSON types see also


smaller than all other types


end of object


double precision floating point value


character string, stored in utf8


an embedded object


an embedded array


binary data


Undefined type.




boolean type


date type


null type


regular expression, a pattern with options


deprecated / will be redesigned


deprecated / use CodeWScope


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


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


32 bit signed integer


Updated to a Date with value next OpTime on insert.


64 bit integer


max type that is not MaxKey


larger than all other types

Formatting mode for generating JSON from BSON.

See <> for details.


strict RFC format


10gen format, which is close to JS format.

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


Javascript JSON compatible.

the query field 'options' can have these bits set:


Tailable means cursor is not closed when the last data is retrieved.

rather, the cursor marks the final object's position. you can resume using the cursor later, from where it was located, if more data were received. Set on dbQuery and dbGetMore.

like any "latent cursor", the cursor may become invalid at some point -- for example if that final object it references were deleted. Thus, you should be prepared to requery if you get back ResultFlag_CursorNotFound.


allow query of replica slave.

normally these return an error except for namespace "local".


The server normally times out idle cursors after an inactivy period to prevent excess memory uses Set this option to prevent that.


Use with QueryOption_CursorTailable.

If we are at the end of the data, block for a while rather than returning no data. After a timeout period, we do return as normal.


Stream the data down full blast in multiple "more" packages, on the assumption that the client will fully read all data queried.

Faster when you are pulling a lot of data and know you want to pull it all down. Note: it is not allowed to not read all the data unless you close the connection.

Use the query( boost::function<void(const BSONObj&)> f, ... ) version of the connection's query() method, and it will take care of all the details for you.


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


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

(Default is update a single document and stop.)

Function Documentation

BSONObj mongo::fromjson ( const char *  str,
int *  len = NULL 

len will be size of JSON object in text chars.

BSONObj mongo::fromjson ( const string &  str  ) 

Create a BSONObj from a JSON <> string.

In addition to the JSON extensions extensions described here <>, this function accepts certain 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 ) are converted to utf8.

MsgAssertionException if parsing fails. The message included with this assertion includes a rough indication of where parsing failed.
Generated on Fri Apr 22 11:07:38 2011 for MongoDB by  doxygen 1.6.3