23 #include <boost/thread/locks.hpp>
24 #include <boost/thread/mutex.hpp>
26 #include "mongo/config.h"
28 #include "mongo/base/string_data.h"
29 #include "mongo/client/bulk_operation_builder.h"
30 #include "mongo/client/exceptions.h"
31 #include "mongo/client/export_macros.h"
32 #include "mongo/client/index_spec.h"
33 #include "mongo/client/write_concern.h"
34 #include "mongo/client/write_options.h"
36 #include "mongo/logger/log_severity.h"
37 #include "mongo/platform/atomic_word.h"
38 #include "mongo/stdx/functional.h"
39 #include "mongo/util/mongoutils/str.h"
40 #include "mongo/util/net/message.h"
41 #include "mongo/util/net/message_port.h"
46 enum MONGO_CLIENT_API QueryOptions {
69 QueryOption_OplogReplay = 1 << 3,
98 QueryOption_OplogReplay |
108 enum MONGO_CLIENT_API WriteOptions {
110 WriteOption_FromWriteback = 1 << 31
119 enum MONGO_CLIENT_API ReservedOptions {
120 Reserved_InsertOption_ContinueOnError = 1 << 0 ,
121 Reserved_FromWriteback = 1 << 1
124 enum MONGO_CLIENT_API ReadPreference {
156 class MONGO_CLIENT_API DBClientBase;
157 class MONGO_CLIENT_API DBClientConnection;
190 enum ConnectionType { INVALID , MASTER , PAIR , SET , CUSTOM };
200 _servers.push_back( server );
204 ConnectionString( ConnectionType type ,
const std::string& s ,
const std::string& setName =
"" ) {
211 verify( _servers.size() == 1 );
214 verify( _setName.size() );
215 verify( _servers.size() >= 1 );
218 verify( _servers.size() == 2 );
221 verify( _servers.size() > 0 );
227 ConnectionString(
const std::string& s , ConnectionType favoredMultipleType ) {
231 if ( _type != INVALID ) {
234 else if ( _servers.size() == 1 ) {
238 _type = favoredMultipleType;
239 verify( _type == SET );
244 bool isValid()
const {
return _type != INVALID; }
246 std::string toString()
const {
return _string; }
248 DBClientBase* connect( std::string& errmsg,
double socketTimeout = 0 )
const;
250 std::string getSetName()
const {
return _setName; }
252 const std::vector<HostAndPort>& getServers()
const {
return _servers; }
254 ConnectionType type()
const {
return _type; }
256 const std::string& getUser()
const {
return _user; }
258 const std::string& getPassword()
const {
return _password; }
260 const BSONObj& getOptions()
const {
return _options; }
262 const std::string& getDatabase()
const {
return _database; }
272 static ConnectionString MONGO_CLIENT_FUNC parse(
const std::string& address , std::string& errmsg );
274 static ConnectionString MONGO_CLIENT_FUNC parseDeprecated(
const std::string& address , std::string& errmsg );
276 static std::string MONGO_CLIENT_FUNC typeToString( ConnectionType type );
291 double socketTimeout ) = 0;
295 boost::lock_guard<boost::mutex> lk( _connectHookMutex );
299 static ConnectionHook* getConnectionHook() {
300 boost::lock_guard<boost::mutex> lk( _connectHookMutex );
305 bool operator<(
const ConnectionString& other)
const {
306 return _string < other._string;
314 static ConnectionString mock(
const HostAndPort& server ) {
315 ConnectionString connStr;
316 connStr._servers.push_back( server );
317 connStr._string = server.toString();
322 ConnectionString( ConnectionType type,
323 const std::string& user,
324 const std::string& password,
325 const std::string& servers,
326 const std::string& database,
327 const std::string& setName,
328 const BSONObj& options )
331 , _setName( setName )
333 , _password( password )
334 , _database( database )
335 , _options( options ) {
337 _fillServers( servers,
false );
340 verify( _servers.size() == 1 );
343 verify( _setName.size() );
344 verify( _servers.size() >= 1 );
347 verify( _servers.size() == 2 );
350 verify( _servers.size() > 0 );
356 static ConnectionString _parseURL(
const std::string& url, std::string& errmsg );
358 void _fillServers( std::string s,
bool legacy =
true );
361 BSONObj _makeAuthObjFromOptions(
int maxWireVersion)
const;
363 ConnectionType _type;
364 std::vector<HostAndPort> _servers;
366 std::string _setName;
369 std::string _password;
371 std::string _database;
374 static boost::mutex _connectHookMutex;
375 static ConnectionHook* _connectHook;
379 class DBClientCursor;
380 class DBClientCursorBatchIterator;
396 Query(
const std::string &json);
397 Query(
const char * json);
414 Query&
sort(
const std::string &field,
int asc = 1) {
sort( BSON( field << asc ) );
return *
this; }
422 Query& hint(
const std::string& indexName);
428 Query& maxTimeMs(
int millis);
471 Query& where(
const std::string &jscode) {
return where(jscode,
BSONObj()); }
479 Query& readPref(ReadPreference pref,
const BSONArray& tags);
484 bool isComplex(
bool * hasDollar = 0 )
const;
485 BSONObj getModifiers()
const;
486 static bool MONGO_CLIENT_FUNC isComplex(
const BSONObj& obj,
bool* hasDollar = 0);
488 BSONObj getFilter()
const;
489 BSONObj getSort()
const;
490 BSONElement getHint()
const;
491 BSONObj getReadPref()
const;
492 int getMaxTimeMs()
const;
493 bool isExplain()
const;
498 static bool MONGO_CLIENT_FUNC hasReadPreference(
const BSONObj& queryObj);
499 bool hasReadPreference()
const;
500 bool hasHint()
const;
501 bool hasMaxTimeMs()
const;
503 std::string toString()
const;
504 operator std::string()
const {
return toString(); }
508 void appendComplex(
const char *fieldName,
const T& val ) {
511 b.appendElements(obj);
512 b.append(fieldName, val);
535 int ntoskip,
int ntoreturn,
int options )
536 : _ns( ns ), _ntoskip( ntoskip ), _ntoreturn( ntoreturn ), _options( options ),
537 _query( query.
getOwned() ), _fields( fields.
getOwned() ) , _queryObj( _query ) {
542 bool isEmpty()
const {
return _ns.size() == 0; }
544 bool isExplain()
const {
return _queryObj.isExplain(); }
545 BSONObj filter()
const {
return _queryObj.getFilter(); }
547 BSONElement hint()
const {
return _queryObj.getHint(); }
548 BSONObj sort()
const {
return _queryObj.getSort(); }
549 BSONObj query()
const {
return _query; }
550 BSONObj fields()
const {
return _fields; }
551 BSONObj* fieldsData() {
return &_fields; }
554 const BSONObj* fieldsPtr()
const {
return &_fields; }
556 std::string ns()
const {
return _ns; }
557 int ntoskip()
const {
return _ntoskip; }
558 int ntoreturn()
const {
return _ntoreturn; }
559 int options()
const {
return _options; }
563 std::string toString()
const {
565 BSON(
"ns" << _ns <<
"n2skip" << _ntoskip <<
"n2return" << _ntoreturn <<
"options" << _options
566 <<
"query" << _query <<
"fields" << _fields );
575 #define MONGO_QUERY(x) ::mongo::Query( BSON(x) )
579 MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC
nsGetDB(
const std::string &ns );
582 MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC
nsGetCollection(
const std::string &ns );
591 virtual bool call(
Message &toSend,
Message &response,
bool assertOk=
true , std::string * actualServer = 0 ) = 0;
592 virtual void say(
Message &toSend,
bool isRetry =
false , std::string * actualServer = 0 ) = 0;
593 virtual void sayPiggyBack(
Message &toSend ) = 0;
595 virtual bool recv(
Message& m ) { verify(
false);
return false; }
597 virtual void checkResponse(
const char* data,
int nReturned,
bool* retry = NULL, std::string* targetHost = NULL ) {
598 if( retry ) *retry =
false;
if( targetHost ) *targetHost =
"";
600 virtual bool lazySupported()
const = 0;
608 virtual std::auto_ptr<DBClientCursor> query(
const std::string &ns,
Query query,
int nToReturn = 0,
int nToSkip = 0,
609 const BSONObj *fieldsToReturn = 0,
int queryOptions = 0 ,
int batchSize = 0 ) = 0;
611 virtual void insert(
const std::string &ns,
BSONObj obj ,
int flags=0,
const WriteConcern* wc=NULL ) = 0;
613 virtual void insert(
const std::string &ns,
const std::vector< BSONObj >& v ,
int flags=0,
const WriteConcern* wc=NULL ) = 0;
615 virtual void remove(
const std::string &ns,
Query query,
bool justOne =
false,
const WriteConcern* wc=NULL ) = 0;
617 virtual void remove(
const std::string &ns,
Query query,
int flags,
const WriteConcern* wc=NULL ) = 0;
619 virtual void update(
const std::string &ns,
622 bool upsert =
false,
bool multi =
false,
const WriteConcern* wc=NULL ) = 0;
632 virtual BSONObj findOne(
const std::string &ns,
const Query& query,
const BSONObj *fieldsToReturn = 0,
int queryOptions = 0);
637 void findN(std::vector<BSONObj>& out,
const std::string&ns,
Query query,
int nToReturn,
int nToSkip = 0,
const BSONObj *fieldsToReturn = 0,
int queryOptions = 0,
int batchSize = 0);
652 virtual std::string getServerAddress()
const = 0;
655 virtual std::auto_ptr<DBClientCursor> getMore(
const std::string &ns,
long long cursorId,
int nToReturn = 0,
int options = 0 ) = 0;
670 _cachedAvailableOptions( (enum QueryOptions)0 ),
671 _haveCachedAvailableOptions(false) { }
679 bool simpleCommand(
const std::string &dbname,
BSONObj *info,
const std::string &command);
694 virtual bool runCommand(
const std::string &dbname,
const BSONObj& cmd,
BSONObj &info,
720 void auth(
const BSONObj& params);
729 bool auth(
const std::string &dbname,
const std::string &username,
const std::string &pwd, std::string& errmsg,
bool digestPassword =
true);
738 virtual void logout(
const std::string& dbname,
BSONObj& info);
743 virtual unsigned long long count(
const std::string &ns,
const Query& query =
Query(),
int options=0,
int limit=0,
int skip=0 );
745 static std::string MONGO_CLIENT_FUNC
createPasswordDigest(
const std::string &username,
const std::string &clearTextPassword);
755 virtual bool isMaster(
bool& isMaster,
BSONObj *info=0);
773 bool createCollection(
774 const std::string &ns,
797 bool createCollectionWithOptions(
798 const std::string &ns,
810 std::string getLastError(
const std::string& db,
818 std::string getLastError(
bool fsync =
false,
bool j =
false,
int w = 0,
int wtimeout = 0);
827 virtual BSONObj getLastErrorDetailed(
const std::string& db,
835 virtual BSONObj getLastErrorDetailed(
bool fsync =
false,
bool j =
false,
int w = 0,
int wtimeout = 0);
840 static std::string MONGO_CLIENT_FUNC getLastErrorString(
const BSONObj& res );
854 bool resetError() {
return simpleCommand(
"admin", 0,
"reseterror"); }
861 std::string db =
nsGetDB( ns );
863 uassert( 10011 ,
"no collection name", coll.size() );
866 if ( info == NULL ) {
870 bool res = runCommand( db.c_str() , BSON(
"drop" << coll ) , *info );
878 return simpleCommand(dbname, info,
"repairDatabase");
900 bool copyDatabase(
const std::string& fromdb,
901 const std::string& todb,
902 const std::string& fromhost =
"",
903 const std::string& mechanism =
"DEFAULT",
904 const std::string& username =
"",
905 const std::string& password =
"",
918 bool setDbProfilingLevel(
const std::string &dbname, ProfilingLevel level,
BSONObj *info = 0);
919 bool getDbProfilingLevel(
const std::string &dbname, ProfilingLevel& level,
BSONObj *info = 0);
926 MROutput(
const char* collection) : out(BSON(
"replace" << collection)) {}
927 MROutput(
const std::string& collection) : out(BSON(
"replace" << collection)) {}
958 const std::string &ns,
959 const std::string &jsmapf,
960 const std::string &jsreducef,
986 const StringData& ns,
987 const StringData& jsreduce,
988 std::vector<BSONObj>* output,
992 const StringData& finalize =
""
1002 void groupWithKeyFunction(
1003 const StringData& ns,
1004 const StringData& jsreduce,
1005 std::vector<BSONObj>* output,
1008 const StringData& jskey =
"",
1009 const StringData& finalize =
""
1023 const StringData& ns,
1024 const StringData& field,
1042 const StringData& ns,
1045 bool upsert =
false,
1046 bool returnNew =
false,
1062 const StringData& ns,
1083 bool eval(
const std::string &dbname,
const std::string &jscode,
BSONObj& info,
BSONElement& retValue,
BSONObj *args = 0);
1088 bool validate(
const std::string &ns ,
bool scandata=
true ) {
1091 return runCommand(
nsGetDB( ns ).c_str() , cmd , info );
1097 bool eval(
const std::string &dbname,
const std::string &jscode);
1099 bool eval(
const std::string &dbname,
const std::string &jscode, T parm1) {
1105 return eval(dbname, jscode, info, retValue, &args);
1109 template<
class T,
class NumType >
1110 bool eval(
const std::string &dbname,
const std::string &jscode, T parm1, NumType& ret) {
1116 if ( !eval(dbname, jscode, info, retValue, &args) )
1118 ret = (NumType) retValue.
number();
1127 std::list<std::string> getDatabaseNames();
1132 std::list<std::string> getCollectionNames(
const std::string& db,
1139 std::list<BSONObj> getCollectionInfos(
const std::string& db,
1153 std::auto_ptr<DBClientCursor> enumerateCollections(
const std::string& db,
1155 int batchSize = 0 );
1157 bool exists(
const std::string& ns );
1169 return createIndex( ns,
IndexSpec().addKeys(keys) );
1180 virtual void createIndex(
const StringData& ns,
const IndexSpec& descriptor );
1182 virtual std::list<BSONObj> getIndexSpecs(
const std::string &ns,
int options = 0 );
1187 virtual std::list<std::string> getIndexNames(
const std::string& ns,
int options = 0 );
1189 virtual std::auto_ptr<DBClientCursor> enumerateIndexes(
const std::string& ns,
1191 int batchSize = 0 );
1193 virtual void dropIndex(
const std::string& ns ,
BSONObj keys );
1194 virtual void dropIndex(
const std::string& ns ,
const std::string& indexName );
1199 virtual void dropIndexes(
const std::string& ns );
1201 virtual void reIndex(
const std::string& ns );
1203 static std::string genIndexName(
const BSONObj& keys );
1207 bool ret = simpleCommand(dbname, info,
"dropDatabase");
1211 virtual std::string toString()
const = 0;
1221 virtual void setRunCommandHook(RunCommandHookFunc func);
1222 RunCommandHookFunc getRunCommandHook()
const {
1223 return _runCommandHook;
1231 virtual void setPostRunCommandHook(PostRunCommandHookFunc func);
1232 PostRunCommandHookFunc getPostRunCommandHook()
const {
1233 return _postRunCommandHook;
1242 bool isNotMasterErrorString(
const BSONElement& e );
1244 BSONObj _countCmd(
const std::string &ns,
const Query& query,
int options,
int limit,
int skip );
1250 QueryOptions availableOptions();
1252 virtual QueryOptions _lookupAvailableOptions();
1254 virtual void _auth(
const BSONObj& params);
1261 bool _authMongoCR(
const std::string &dbname,
1262 const std::string &username,
1263 const std::string &pwd,
1265 bool digestPassword);
1272 bool _authX509(
const std::string &dbname,
1273 const std::string &username,
1280 PostRunCommandHookFunc _postRunCommandHook;
1281 int _minWireVersion;
1282 int _maxWireVersion;
1286 enum QueryOptions _cachedAvailableOptions;
1287 bool _haveCachedAvailableOptions;
1289 void _buildGroupObj(
1290 const StringData& ns,
1291 const StringData& jsreduce,
1294 const StringData& finalize,
1299 const StringData& ns,
1302 std::vector<BSONObj>* output
1305 void _findAndModify(
1306 const StringData& ns,
1316 std::auto_ptr<DBClientCursor> _legacyCollectionInfo(
1317 const std::string& db,
1332 static AtomicInt64 ConnectionIdSequence;
1333 long long _connectionId;
1334 const boost::scoped_ptr<DBClientWriter> _wireProtocolWriter;
1335 const boost::scoped_ptr<DBClientWriter> _commandWriter;
1337 int _maxBsonObjectSize;
1338 int _maxMessageSizeBytes;
1339 int _maxWriteBatchSize;
1341 const std::string& ns,
1342 const std::vector<WriteOperation*>& writes,
1348 static const uint64_t INVALID_SOCK_CREATION_TIME;
1356 long long getConnectionId()
const {
return _connectionId; }
1358 const WriteConcern& getWriteConcern()
const {
return _writeConcern; }
1359 void setWriteConcern(
const WriteConcern& w ) { _writeConcern = w; }
1361 void setWireVersions(
int minWireVersion,
int maxWireVersion ){
1362 _minWireVersion = minWireVersion;
1363 _maxWireVersion = maxWireVersion;
1366 int getMinWireVersion() {
return _minWireVersion; }
1367 int getMaxWireVersion() {
return _maxWireVersion; }
1368 int getMaxBsonObjectSize() {
return _maxBsonObjectSize; }
1369 int getMaxMessageSizeBytes() {
return _maxMessageSizeBytes; }
1370 int getMaxWriteBatchSize() {
return _maxWriteBatchSize; }
1386 virtual std::auto_ptr<DBClientCursor> query(
const std::string &ns,
Query query,
int nToReturn = 0,
int nToSkip = 0,
1387 const BSONObj *fieldsToReturn = 0,
int queryOptions = 0 ,
int batchSize = 0 );
1408 virtual void parallelScan(
1409 const StringData& ns,
1411 std::vector<DBClientCursor*>* cursors,
1415 virtual std::auto_ptr<DBClientCursor> aggregate(
const std::string& ns,
1417 const BSONObj* aggregateOptions = NULL,
1418 int queryOptions = 0);
1429 virtual unsigned long long query( stdx::function<
void(
const BSONObj&)> f,
1430 const std::string& ns,
1432 const BSONObj *fieldsToReturn = 0,
1433 int queryOptions = 0 );
1436 const std::string& ns,
1438 const BSONObj *fieldsToReturn = 0,
1439 int queryOptions = 0 );
1447 virtual std::auto_ptr<DBClientCursor> getMore(
const std::string &ns,
long long cursorId,
int nToReturn = 0,
int options = 0 );
1452 virtual void insert(
1453 const std::string &ns,
1462 virtual void insert(
1463 const std::string &ns,
1464 const std::vector< BSONObj >& v,
1472 virtual void update(
1473 const std::string &ns,
1481 virtual void update(
1482 const std::string &ns,
1511 virtual void remove(
const std::string &ns ,
Query q ,
bool justOne = 0,
const WriteConcern* wc=NULL );
1513 virtual void remove(
const std::string &ns ,
Query query,
int flags,
const WriteConcern* wc=NULL );
1515 virtual bool isFailed()
const = 0;
1520 virtual bool isStillConnected() = 0;
1522 virtual void killCursor(
long long cursorID ) = 0;
1524 virtual bool callRead(
Message& toSend ,
Message& response ) = 0;
1527 virtual ConnectionString::ConnectionType type()
const = 0;
1529 virtual double getSoTimeout()
const = 0;
1531 virtual uint64_t getSockCreationMicroSec()
const {
1532 return INVALID_SOCK_CREATION_TIME;
1535 virtual void reset() {}
1561 clientSet(cp), _failed(false), autoReconnect(_autoReconnect), autoReconnectBackoff(1000, 2000), _so_timeout(so_timeout) {
1562 _numConnections.fetchAndAdd(1);
1566 _numConnections.fetchAndAdd(-1);
1578 virtual bool connect(
const HostAndPort& server, std::string& errmsg);
1581 bool connect(
const std::string& server, std::string& errmsg) {
1595 if( !connect(
HostAndPort(serverHostname), errmsg) )
1606 virtual void logout(
const std::string& dbname,
BSONObj& info);
1608 virtual std::auto_ptr<DBClientCursor> query(
const std::string &ns,
Query query=
Query(),
int nToReturn = 0,
int nToSkip = 0,
1609 const BSONObj *fieldsToReturn = 0,
int queryOptions = 0 ,
int batchSize = 0 );
1612 const std::string& ns,
1614 const BSONObj *fieldsToReturn,
1617 virtual bool runCommand(
const std::string &dbname,
1632 std::string toString()
const {
1633 std::stringstream ss;
1634 ss << _serverString;
1635 if ( !_serverAddrString.empty() ) ss <<
" (" << _serverAddrString <<
")";
1636 if ( _failed ) ss <<
" failed";
1640 std::string getServerAddress()
const {
return _serverString; }
1641 const HostAndPort& getServerHostAndPort()
const {
return _server; }
1643 virtual void killCursor(
long long cursorID );
1644 virtual bool callRead( Message& toSend , Message& response ) {
return call( toSend , response ); }
1645 virtual void say( Message &toSend,
bool isRetry =
false , std::string * actualServer = 0 );
1646 virtual bool recv( Message& m );
1647 virtual void checkResponse(
const char *data,
int nReturned,
bool* retry = NULL, std::string* host = NULL );
1648 virtual bool call( Message &toSend, Message &response,
bool assertOk =
true , std::string * actualServer = 0 );
1649 virtual ConnectionString::ConnectionType type()
const {
return ConnectionString::MASTER; }
1650 void setSoTimeout(
double timeout);
1651 double getSoTimeout()
const {
return _so_timeout; }
1653 virtual bool lazySupported()
const {
return true; }
1655 static int MONGO_CLIENT_FUNC getNumConnections() {
1656 return _numConnections.load();
1669 void setReplSetClientCallback(DBClientReplicaSet* rsClient);
1671 static void MONGO_CLIENT_FUNC setLazyKillCursor(
bool lazy ) { _lazyKillCursor = lazy; }
1672 static bool MONGO_CLIENT_FUNC getLazyKillCursor() {
return _lazyKillCursor; }
1674 uint64_t getSockCreationMicroSec()
const;
1677 virtual void _auth(
const BSONObj& params);
1678 virtual void sayPiggyBack( Message &toSend );
1680 DBClientReplicaSet *clientSet;
1681 boost::scoped_ptr<MessagingPort> p;
1682 boost::scoped_ptr<SockAddr> server;
1684 const bool autoReconnect;
1685 Backoff autoReconnectBackoff;
1686 HostAndPort _server;
1687 std::string _serverString;
1688 std::string _serverAddrString;
1689 void _checkConnection();
1692 void checkConnection() {
if( _failed ) _checkConnection(); }
1694 std::map<std::string, BSONObj> authCache;
1696 bool _connect( std::string& errmsg );
1698 static AtomicInt32 _numConnections;
1699 static bool _lazyKillCursor;
1702 SSLManagerInterface* sslManager();
1708 MONGO_CLIENT_API
bool MONGO_CLIENT_FUNC
serverAlive(
const std::string &uri );
1710 MONGO_CLIENT_API BSONElement MONGO_CLIENT_FUNC getErrField(
const BSONObj& result );
1711 MONGO_CLIENT_API
bool MONGO_CLIENT_FUNC hasErrField(
const BSONObj& result );
1713 MONGO_CLIENT_API
inline std::ostream& MONGO_CLIENT_FUNC operator<<( std::ostream &s,
const Query &q ) {
1714 return s << q.toString();
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...
Definition: bson_field.h:73
Represents a single server side write operation and encapsulates the process for encoding the operati...
Definition: write_operation.h:31
DBClientConnection(bool _autoReconnect=false, DBClientReplicaSet *cp=0, double so_timeout=0)
Definition: dbclientinterface.h:1560
DB "commands" Basically just invocations of connection.
Definition: dbclientinterface.h:662
MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC nsGetDB(const std::string &ns)
bool eval(const std::string &dbname, const std::string &jscode, T parm1, NumType &ret)
eval invocation with one parm to server and one numeric field (either int or double) returned ...
Definition: dbclientinterface.h:1110
Definition: message.h:298
QueryOption_SlaveOk
allow query of replica slave.
Definition: dbclientinterface.h:59
the main MongoDB namespace
Definition: bulk_operation_builder.h:24
the idea here is to make one liners easy.
Definition: str.h:44
Class for constructing and executing bulk operations against MongoDB via a fluent API...
Definition: bulk_operation_builder.h:54
QueryOption_Exhaust
Stream the data down full blast in multiple "more" packages, on the assumption that the client will f...
Definition: dbclientinterface.h:88
This implicitly converts from char*, string, and BSONObj to be an argument to mapreduce You shouldn't...
Definition: dbclientinterface.h:925
ReadPreference_SecondaryOnly
Read from secondary if available, otherwise error.
Definition: dbclientinterface.h:130
ReadPreference_SecondaryPreferred
Read from a secondary if available, otherwise read from the primary.
Definition: dbclientinterface.h:130
bool repairDatabase(const std::string &dbname, BSONObj *info=0)
Perform a repair and compaction of the specified database.
Definition: dbclientinterface.h:877
MONGO_CLIENT_API std::string MONGO_CLIENT_FUNC nsGetCollection(const std::string &ns)
BSONObjBuilder & append(const BSONElement &e)
append element to the object we are building
Definition: bsonobjbuilder.h:109
virtual bool dropCollection(const std::string &ns, BSONObj *info=NULL)
Delete the specified collection.
Definition: dbclientinterface.h:860
Represents a full query description, including all options required for the query to be passed on to ...
Definition: dbclientinterface.h:521
stdx::function< void(const BSONObj &, const std::string &)> PostRunCommandHookFunc
Similar to above, but for running a function on a command response after a command has been run...
Definition: dbclientinterface.h:1230
void createIndex(const StringData &ns, const BSONObj &keys)
Create an index on the collection 'ns' as described by the given keys.
Definition: dbclientinterface.h:1168
Utility for creating a BSONObj.
Definition: bsonobjbuilder.h:49
BSONObj done()
Fetch the object we have built.
Definition: bsonobjbuilder.h:580
BSONObj getOwned() const
assure the data buffer is under the control of this BSONObj and not a remote buffer ...
virtual bool dropDatabase(const std::string &dbname, BSONObj *info=0)
Erase / drop an entire database.
Definition: dbclientinterface.h:1206
Class representing the result of a write operations sent to the server.
Definition: write_result.h:33
A basic connection to the database.
Definition: dbclientinterface.h:1550
QueryOption_PartialResults
When sharded, this means its ok to return partial results Usually we will fail a query if all require...
Definition: dbclientinterface.h:94
bool connect(const std::string &server, std::string &errmsg)
Compatibility connect now that HostAndPort has an explicit constructor.
Definition: dbclientinterface.h:1581
Use this class to connect to a replica set of servers.
Definition: dbclient_rs.h:42
ConnectionString can parse MongoDB URIs with the following format:
Definition: dbclientinterface.h:187
bool isFailed() const
Definition: dbclientinterface.h:1626
QueryOption_NoCursorTimeout
The server normally times out idle cursors after an inactivity period to prevent excess memory uses S...
Definition: dbclientinterface.h:74
logger::LogSeverity _logLevel
controls how chatty the client is about network errors & such.
Definition: dbclientinterface.h:665
Class to encapsulate client side "Write Concern" concept.
Definition: write_concern.h:35
void connect(const std::string &serverHostname)
Connect to a Mongo database server.
Definition: dbclientinterface.h:1593
Definition: assert_util.h:130
iterate over objects in current batch only - will not cause a network call
Definition: dbclientcursor.h:229
ReadPreference_PrimaryOnly
Read from primary only.
Definition: dbclientinterface.h:130
Name of a process on the network.
Definition: hostandport.h:36
MONGO_CLIENT_API bool MONGO_CLIENT_FUNC serverAlive(const std::string &uri)
pings server to check if it's up
stdx::function< void(BSONObjBuilder *)> RunCommandHookFunc
A function type for runCommand hooking; the function takes a pointer to a BSONObjBuilder and returns ...
Definition: dbclientinterface.h:1220
The interface that any db connection should implement.
Definition: dbclientinterface.h:606
bool validate(const std::string &ns, bool scandata=true)
validate a collection, checking for errors and reporting back statistics.
Definition: dbclientinterface.h:1088
double number() const
Retrieve the numeric value of the element.
Definition: bsonelement.h:236
Definition: dbclient_writer.h:27
Definition: dbclientinterface.h:1541
QueryOption_AwaitData
Use with QueryOption_CursorTailable.
Definition: dbclientinterface.h:79
BSONElement represents an "element" in a BSONObj.
Definition: bsonelement.h:55
virtual std::auto_ptr< DBClientCursor > query(const std::string &ns, Query query, int nToReturn=0, int nToSkip=0, const BSONObj *fieldsToReturn=0, int queryOptions=0, int batchSize=0)
send a query to the database.
Represents a Mongo query expression.
Definition: dbclientinterface.h:387
ReadPreference_Nearest
Read from any member.
Definition: dbclientinterface.h:130
abstract class that implements the core db operations
Definition: dbclientinterface.h:1329
Definition: index_spec.h:29
bool resetError()
Reset the previous error state for this connection (accessed via getLastError and getPrevError)...
Definition: dbclientinterface.h:854
bool isStillConnected()
if not checked recently, checks whether the underlying socket/sockets are still valid ...
Definition: dbclientinterface.h:1628
RunCommandHookFunc _runCommandHook
These functions will be executed by the driver on runCommand calls.
Definition: dbclientinterface.h:1279
ReadPreference_PrimaryPreferred
Read from primary if available, otherwise a secondary.
Definition: dbclientinterface.h:130
ProfilingLevel
The Mongo database provides built-in performance profiling capabilities.
Definition: dbclientinterface.h:912
Query & sort(const std::string &field, int asc=1)
Add a sort (ORDER BY) criteria to the query expression.
Definition: dbclientinterface.h:414
interface that handles communication with the db
Definition: dbclientinterface.h:587
Definition: dbclientinterface.h:284
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary represent...
Definition: bsonobj.h:78
QueryOption_CursorTailable
Tailable means cursor is not closed when the last data is retrieved.
Definition: dbclientinterface.h:55
Definition: message_port.h:68