mongo::DBClientWithCommands Class Reference

#include <dbclient.h>

Inheritance diagram for mongo::DBClientWithCommands:
Inheritance graph
[legend]

List of all members.

Public Types

enum  ProfilingLevel { ProfileOff = 0, ProfileSlow = 1, ProfileAll = 2 }

Public Member Functions

virtual bool auth (const string &dbname, const string &username, const string &pwd, string &errmsg, bool digestPassword=true)
bool copyDatabase (const string &fromdb, const string &todb, const string &fromhost="", BSONObj *info=0)
virtual unsigned long long count (const string &ns, const BSONObj &query=BSONObj(), int options=0, int limit=0, int skip=0)
bool createCollection (const string &ns, long long size=0, bool capped=false, int max=0, BSONObj *info=0)
string createPasswordDigest (const string &username, const string &clearTextPassword)
 DBClientWithCommands ()
virtual bool dropCollection (const string &ns)
virtual bool dropDatabase (const string &dbname, BSONObj *info=0)
virtual void dropIndex (const string &ns, const string &indexName)
virtual void dropIndex (const string &ns, BSONObj keys)
virtual void dropIndexes (const string &ns)
virtual bool ensureIndex (const string &ns, BSONObj keys, bool unique=false, const string &name="", bool cache=true)
template<class T , class NumType >
bool eval (const string &dbname, const string &jscode, T parm1, NumType &ret)
template<class T >
bool eval (const string &dbname, const string &jscode, T parm1)
bool eval (const string &dbname, const string &jscode)
bool eval (const string &dbname, const string &jscode, BSONObj &info, BSONElement &retValue, BSONObj *args=0)
bool exists (const string &ns)
string genIndexName (const BSONObj &keys)
list< string > getCollectionNames (const string &db)
list< string > getDatabaseNames ()
bool getDbProfilingLevel (const string &dbname, ProfilingLevel &level, BSONObj *info=0)
virtual auto_ptr< DBClientCursorgetIndexes (const string &ns)
string getLastError ()
virtual BSONObj getLastErrorDetailed ()
BSONObj getPrevError ()
virtual bool isMaster (bool &isMaster, BSONObj *info=0)
BSONObj mapreduce (const string &ns, const string &jsmapf, const string &jsreducef, BSONObj query=BSONObj(), const string &output="")
string nsGetCollection (const string &ns)
string nsGetDB (const string &ns)
virtual void reIndex (const string &ns)
bool repairDatabase (const string &dbname, BSONObj *info=0)
bool resetError ()
virtual void resetIndexCache ()
virtual bool runCommand (const string &dbname, const BSONObj &cmd, BSONObj &info, int options=0)
bool setDbProfilingLevel (const string &dbname, ProfilingLevel level, BSONObj *info=0)
bool simpleCommand (const string &dbname, BSONObj *info, const string &command)
virtual string toString ()=0
bool validate (const string &ns, bool scandata=true)

Static Public Member Functions

static string getLastErrorString (const BSONObj &res)

Public Attributes

int _logLevel

Protected Member Functions

BSONObj _countCmd (const string &ns, const BSONObj &query, int options, int limit, int skip)
enum QueryOptions availableOptions ()
bool isOk (const BSONObj &)

Private Attributes

enum QueryOptions _cachedAvailableOptions
bool _haveCachedAvailableOptions
set< string > _seenIndexes

Detailed Description

DB "commands" Basically just invocations of connection.$cmd.findOne({...});

Definition at line 378 of file dbclient.h.


Member Enumeration Documentation

The Mongo database provides built-in performance profiling capabilities. Uset setDbProfilingLevel() to enable. Profiling information is then written to the system.profiling collection, which one can then query.

Enumerator:
ProfileOff 
ProfileSlow 
ProfileAll 

Definition at line 522 of file dbclient.h.


Constructor & Destructor Documentation

mongo::DBClientWithCommands::DBClientWithCommands (  )  [inline]

Definition at line 384 of file dbclient.h.


Member Function Documentation

BSONObj mongo::DBClientWithCommands::_countCmd ( const string &  ns,
const BSONObj query,
int  options,
int  limit,
int  skip 
) [protected]
virtual bool mongo::DBClientWithCommands::auth ( const string &  dbname,
const string &  username,
const string &  pwd,
string &  errmsg,
bool  digestPassword = true 
) [virtual]

Authorize access to a particular database. Authentication is separate for each database on the server -- you may authenticate for any number of databases on a single connection. The "admin" database is special and once authenticated provides access to all databases on the server.

Parameters:
digestPassword if password is plain text, set this to true. otherwise assumed to be pre-digested
Returns:
true if successful

Reimplemented in mongo::DBClientConnection, and mongo::DBClientReplicaSet.

enum QueryOptions mongo::DBClientWithCommands::availableOptions (  )  [protected]
bool mongo::DBClientWithCommands::copyDatabase ( const string &  fromdb,
const string &  todb,
const string &  fromhost = "",
BSONObj info = 0 
)

Copy database from one server or name to another server or name.

Generally, you should dropDatabase() first as otherwise the copied information will MERGE into whatever data is already present in this database.

For security reasons this function only works when you are authorized to access the "admin" db. However, if you have access to said db, you can copy any database from one place to another. TODO: this needs enhancement to be more flexible in terms of security.

This method provides a way to "rename" a database by copying it to a new db name and location. The copy is "repaired" and compacted.

fromdb database name from which to copy. todb database name to copy to. fromhost hostname of the database (and optionally, ":port") from which to copy the data. copies from self if "".

returns true if successful

virtual unsigned long long mongo::DBClientWithCommands::count ( const string &  ns,
const BSONObj query = BSONObj(),
int  options = 0,
int  limit = 0,
int  skip = 0 
) [virtual]

count number of objects in collection ns that match the query criteria specified throws UserAssertion if database returns an error

Reimplemented in mongo::DBDirectClient.

bool mongo::DBClientWithCommands::createCollection ( const string &  ns,
long long  size = 0,
bool  capped = false,
int  max = 0,
BSONObj info = 0 
)

Create a new collection in the database. Normally, collection creation is automatic. You would use this function if you wish to specify special options on creation.

If the collection already exists, no action occurs.

Parameters:
ns fully qualified collection name
size desired initial extent size for the collection. Must be <= 1000000000 for normal collections. For fixed size (capped) collections, this size is the total/max size of the collection.
capped if true, this is a fixed size collection (where old data rolls out).
max maximum number of objects if capped (optional).

returns true if successful.

string mongo::DBClientWithCommands::createPasswordDigest ( const string &  username,
const string &  clearTextPassword 
)
virtual bool mongo::DBClientWithCommands::dropCollection ( const string &  ns  )  [inline, virtual]

Delete the specified collection.

Definition at line 478 of file dbclient.h.

virtual bool mongo::DBClientWithCommands::dropDatabase ( const string &  dbname,
BSONObj info = 0 
) [inline, virtual]

Erase / drop an entire database

Definition at line 658 of file dbclient.h.

virtual void mongo::DBClientWithCommands::dropIndex ( const string &  ns,
const string &  indexName 
) [virtual]
virtual void mongo::DBClientWithCommands::dropIndex ( const string &  ns,
BSONObj  keys 
) [virtual]
virtual void mongo::DBClientWithCommands::dropIndexes ( const string &  ns  )  [virtual]

drops all indexes for the collection

virtual bool mongo::DBClientWithCommands::ensureIndex ( const string &  ns,
BSONObj  keys,
bool  unique = false,
const string &  name = "",
bool  cache = true 
) [virtual]

Create an index if it does not already exist. ensureIndex calls are remembered so it is safe/fast to call this function many times in your code.

Parameters:
ns collection to be indexed
keys the "key pattern" for the index. e.g., { name : 1 }
unique if true, indicates that key uniqueness should be enforced for this index
name if not isn't specified, it will be created from the keys (recommended)
cache if set to false, the index cache for the connection won't remember this call
Returns:
whether or not sent message to db. should be true on first call, false on subsequent unless resetIndexCache was called
template<class T , class NumType >
bool mongo::DBClientWithCommands::eval ( const string &  dbname,
const string &  jscode,
parm1,
NumType &  ret 
) [inline]

eval invocation with one parm to server and one numeric field (either int or double) returned

Definition at line 598 of file dbclient.h.

template<class T >
bool mongo::DBClientWithCommands::eval ( const string &  dbname,
const string &  jscode,
parm1 
) [inline]

Definition at line 587 of file dbclient.h.

bool mongo::DBClientWithCommands::eval ( const string &  dbname,
const string &  jscode 
)
bool mongo::DBClientWithCommands::eval ( const string &  dbname,
const string &  jscode,
BSONObj info,
BSONElement retValue,
BSONObj args = 0 
)

Run javascript code on the database server. dbname database SavedContext in which the code runs. The javascript variable 'db' will be assigned to this database when the function is invoked. jscode source code for a javascript function. info the command object which contains any information on the invocation result including the return value and other information. If an error occurs running the jscode, error information will be in info. (try "out() << info.toString()") retValue return value from the jscode function. args args to pass to the jscode function. when invoked, the 'args' variable will be defined for use by the jscode.

returns true if runs ok.

See testDbEval() in dbclient.cpp for an example of usage.

bool mongo::DBClientWithCommands::exists ( const string &  ns  ) 
string mongo::DBClientWithCommands::genIndexName ( const BSONObj keys  ) 
list<string> mongo::DBClientWithCommands::getCollectionNames ( const string &  db  ) 

get a list of all the current collections in db

list<string> mongo::DBClientWithCommands::getDatabaseNames (  ) 

get a list of all the current databases uses the { listDatabases : 1 } command. throws on error

bool mongo::DBClientWithCommands::getDbProfilingLevel ( const string &  dbname,
ProfilingLevel level,
BSONObj info = 0 
)
virtual auto_ptr<DBClientCursor> mongo::DBClientWithCommands::getIndexes ( const string &  ns  )  [virtual]
string mongo::DBClientWithCommands::getLastError (  ) 

Get error result from the last operation on this connection.

Returns:
error message text, or empty string if no error.
virtual BSONObj mongo::DBClientWithCommands::getLastErrorDetailed (  )  [virtual]

Get error result from the last operation on this connection.

Returns:
full error object.

Reimplemented in mongo::SyncClusterConnection.

static string mongo::DBClientWithCommands::getLastErrorString ( const BSONObj res  )  [static]
BSONObj mongo::DBClientWithCommands::getPrevError (  ) 

Return the last error which has occurred, even if not the very last operation.

Returns:
{ err : <error message>="">, nPrev : <how_many_ops_back_occurred>, ok : 1 }

result.err will be null if no error has occurred.

virtual bool mongo::DBClientWithCommands::isMaster ( bool &  isMaster,
BSONObj info = 0 
) [virtual]

returns true in isMaster parm if this db is the current master of a replica pair.

pass in info for more details e.g.: { "ismaster" : 1.0 , "msg" : "not paired" , "ok" : 1.0 }

returns true if command invoked successfully.

bool mongo::DBClientWithCommands::isOk ( const BSONObj  )  [protected]
BSONObj mongo::DBClientWithCommands::mapreduce ( const string &  ns,
const string &  jsmapf,
const string &  jsreducef,
BSONObj  query = BSONObj(),
const string &  output = "" 
)

Run a map/reduce job on the server.

See http://www.mongodb.org/display/DOCS/MapReduce

ns namespace (db+collection name) of input data jsmapf javascript map function code jsreducef javascript reduce function code. query optional query filter for the input output optional permanent output collection name. if not specified server will generate a temporary collection and return its name.

returns a result object which contains: { result : <collection_name>, numObjects : <number_of_objects_scanned>, timeMillis : <job_time>, ok : <1_if_ok>, [, err : <errmsg_if_error>] }

For example one might call: result.getField("ok").trueValue() on the result to check if ok.

string mongo::DBClientWithCommands::nsGetCollection ( const string &  ns  )  [inline]
Returns:
the collection name portion of an ns string

Definition at line 676 of file dbclient.h.

string mongo::DBClientWithCommands::nsGetDB ( const string &  ns  )  [inline]
Returns:
the database name portion of an ns string

Definition at line 667 of file dbclient.h.

virtual void mongo::DBClientWithCommands::reIndex ( const string &  ns  )  [virtual]
bool mongo::DBClientWithCommands::repairDatabase ( const string &  dbname,
BSONObj info = 0 
) [inline]

Perform a repair and compaction of the specified database. May take a long time to run. Disk space must be available equal to the size of the database while repairing.

Definition at line 493 of file dbclient.h.

bool mongo::DBClientWithCommands::resetError (  )  [inline]

Reset the previous error state for this connection (accessed via getLastError and getPrevError). Useful when performing several operations at once and then checking for an error after attempting all operations.

Definition at line 475 of file dbclient.h.

virtual void mongo::DBClientWithCommands::resetIndexCache (  )  [virtual]

clears the index cache, so the subsequent call to ensureIndex for any index will go to the server

virtual bool mongo::DBClientWithCommands::runCommand ( const string &  dbname,
const BSONObj cmd,
BSONObj info,
int  options = 0 
) [virtual]

Run a database command. Database commands are represented as BSON objects. Common database commands have prebuilt helper functions -- see below. If a helper is not available you can directly call runCommand.

Parameters:
dbname database name. Use "admin" for global administrative commands.
cmd the command object to execute. For example, { ismaster : 1 }
info the result object the database returns. Typically has { ok : ..., errmsg : ... } fields set.
options see enum QueryOptions - normally not needed to run a command
Returns:
true if the command returned "ok".
bool mongo::DBClientWithCommands::setDbProfilingLevel ( const string &  dbname,
ProfilingLevel  level,
BSONObj info = 0 
)
bool mongo::DBClientWithCommands::simpleCommand ( const string &  dbname,
BSONObj info,
const string &  command 
)

helper function. run a simple command where the command expression is simply { command : 1 }

Parameters:
info -- where to put result object. may be null if caller doesn't need that info
command -- command name
Returns:
true if the command returned "ok".
virtual string mongo::DBClientWithCommands::toString (  )  [pure virtual]
bool mongo::DBClientWithCommands::validate ( const string &  ns,
bool  scandata = true 
) [inline]

validate a collection, checking for errors and reporting back statistics. this operation is slow and blocking.

Definition at line 576 of file dbclient.h.


Member Data Documentation

Definition at line 692 of file dbclient.h.

Definition at line 693 of file dbclient.h.

controls how chatty the client is about network errors & such. See log.h

Definition at line 382 of file dbclient.h.

Definition at line 379 of file dbclient.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


mongodb
Author(s): Nate Koenig
autogenerated on Fri Jan 11 12:15:54 2013