#include <dbclient.h>
Public Member Functions | |
virtual bool | auth (const string &dbname, const string &username, const string &pwd, string &errmsg, bool digestPassword=true) |
virtual bool | call (Message &toSend, Message &response, bool assertOk=true, string *actualServer=0) |
virtual bool | callRead (Message &toSend, Message &response) |
virtual void | checkResponse (const char *data, int nReturned) |
void | connect (const string &serverHostname) |
virtual bool | connect (const HostAndPort &server, string &errmsg) |
virtual bool | connect (const char *hostname, string &errmsg) |
DBClientConnection (bool _autoReconnect=false, DBClientReplicaSet *cp=0, double so_timeout=0) | |
string | getServerAddress () const |
bool | isFailed () const |
virtual void | killCursor (long long cursorID) |
MessagingPort & | port () |
unsigned long long | query (boost::function< void(DBClientCursorBatchIterator &)> f, const string &ns, Query query, const BSONObj *fieldsToReturn=0, int queryOptions=0) |
unsigned long long | query (boost::function< void(const BSONObj &)> f, const string &ns, Query query, const BSONObj *fieldsToReturn=0, int queryOptions=0) |
virtual auto_ptr< DBClientCursor > | query (const string &ns, Query query=Query(), int nToReturn=0, int nToSkip=0, const BSONObj *fieldsToReturn=0, int queryOptions=0, int batchSize=0) |
virtual void | say (Message &toSend) |
void | setSoTimeout (double to) |
string | toString () |
string | toStringLong () const |
virtual ConnectionString::ConnectionType | type () const |
virtual | ~DBClientConnection () |
Static Public Member Functions | |
static bool | getLazyKillCursor () |
static int | getNumConnections () |
static void | setLazyKillCursor (bool lazy) |
Protected Member Functions | |
void | _checkConnection () |
bool | _connect (string &errmsg) |
void | checkConnection () |
virtual void | recv (Message &m) |
virtual void | sayPiggyBack (Message &toSend) |
Protected Attributes | |
HostAndPort | _server |
string | _serverString |
double | _so_timeout |
map< string, pair< string, string > > | authCache |
const bool | autoReconnect |
DBClientReplicaSet * | clientSet |
bool | failed |
time_t | lastReconnectTry |
boost::scoped_ptr< MessagingPort > | p |
boost::scoped_ptr< SockAddr > | server |
Static Protected Attributes | |
static bool | _lazyKillCursor |
static AtomicUInt | _numConnections |
Friends | |
class | SyncClusterConnection |
A basic connection to the database. This is the main entry point for talking to a simple Mongo setup
Definition at line 779 of file dbclient.h.
mongo::DBClientConnection::DBClientConnection | ( | bool | _autoReconnect = false , |
|
DBClientReplicaSet * | cp = 0 , |
|||
double | so_timeout = 0 | |||
) | [inline] |
_autoReconnect | if true, automatically reconnect on a connection failure | |
cp | used by DBClientReplicaSet. You do not need to specify this parameter | |
timeout | tcp timeout in seconds - this is for read/write, not connect. Connect timeout is fixed, but short, at 5 seconds. |
Definition at line 787 of file dbclient.h.
virtual mongo::DBClientConnection::~DBClientConnection | ( | ) | [inline, virtual] |
Definition at line 792 of file dbclient.h.
void mongo::DBClientConnection::_checkConnection | ( | ) | [protected] |
bool mongo::DBClientConnection::_connect | ( | string & | errmsg | ) | [protected] |
virtual bool mongo::DBClientConnection::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.
digestPassword | if password is plain text, set this to true. otherwise assumed to be pre-digested |
Reimplemented from mongo::DBClientWithCommands.
virtual bool mongo::DBClientConnection::call | ( | Message & | toSend, | |
Message & | response, | |||
bool | assertOk = true , |
|||
string * | actualServer = 0 | |||
) | [virtual] |
actualServer is set to the actual server where they call went if there was a choice (SlaveOk)
Implements mongo::DBConnector.
virtual bool mongo::DBClientConnection::callRead | ( | Message & | toSend, | |
Message & | response | |||
) | [inline, virtual] |
Implements mongo::DBClientBase.
Definition at line 876 of file dbclient.h.
void mongo::DBClientConnection::checkConnection | ( | ) | [inline, protected] |
Definition at line 906 of file dbclient.h.
virtual void mongo::DBClientConnection::checkResponse | ( | const char * | data, | |
int | nReturned | |||
) | [virtual] |
Reimplemented from mongo::DBConnector.
void mongo::DBClientConnection::connect | ( | const string & | serverHostname | ) | [inline] |
Connect to a Mongo database server. Exception throwing version. Throws a UserException if cannot connect.
If autoReconnect is true, you can try to use the DBClientConnection even when false was returned -- it will try to connect again.
serverHostname | host to connect to. can include port number ( 127.0.0.1 , 127.0.0.1:5555 ) |
Definition at line 832 of file dbclient.h.
virtual bool mongo::DBClientConnection::connect | ( | const HostAndPort & | server, | |
string & | errmsg | |||
) | [virtual] |
Connect to a Mongo database server.
If autoReconnect is true, you can try to use the DBClientConnection even when false was returned -- it will try to connect again.
server | server to connect to. | |
errmsg | any relevant error message will appended to the string |
virtual bool mongo::DBClientConnection::connect | ( | const char * | hostname, | |
string & | errmsg | |||
) | [inline, virtual] |
Connect to a Mongo database server.
If autoReconnect is true, you can try to use the DBClientConnection even when false was returned -- it will try to connect again.
serverHostname | host to connect to. can include port number ( 127.0.0.1 , 127.0.0.1:5555 ) If you use IPv6 you must add a port number ( ::1:27017 ) | |
errmsg | any relevant error message will appended to the string |
Definition at line 807 of file dbclient.h.
static bool mongo::DBClientConnection::getLazyKillCursor | ( | ) | [inline, static] |
Definition at line 888 of file dbclient.h.
static int mongo::DBClientConnection::getNumConnections | ( | ) | [inline, static] |
Definition at line 883 of file dbclient.h.
string mongo::DBClientConnection::getServerAddress | ( | ) | const [inline, virtual] |
Implements mongo::DBClientInterface.
Definition at line 873 of file dbclient.h.
bool mongo::DBClientConnection::isFailed | ( | ) | const [inline, virtual] |
Implements mongo::DBClientBase.
Definition at line 859 of file dbclient.h.
virtual void mongo::DBClientConnection::killCursor | ( | long long | cursorID | ) | [virtual] |
Implements mongo::DBClientBase.
MessagingPort& mongo::DBClientConnection::port | ( | ) | [inline] |
Definition at line 861 of file dbclient.h.
unsigned long long mongo::DBClientConnection::query | ( | boost::function< void(DBClientCursorBatchIterator &)> | f, | |
const string & | ns, | |||
Query | query, | |||
const BSONObj * | fieldsToReturn = 0 , |
|||
int | queryOptions = 0 | |||
) |
unsigned long long mongo::DBClientConnection::query | ( | boost::function< void(const BSONObj &)> | f, | |
const string & | ns, | |||
Query | query, | |||
const BSONObj * | fieldsToReturn = 0 , |
|||
int | queryOptions = 0 | |||
) |
Uses QueryOption_Exhaust Exhaust mode sends back all data queries as fast as possible, with no back-and-for for OP_GETMORE. If you are certain you will exhaust the query, it could be useful.
Use DBClientCursorBatchIterator version if you want to do items in large blocks, perhaps to avoid granular locking and such.
virtual auto_ptr<DBClientCursor> mongo::DBClientConnection::query | ( | const string & | ns, | |
Query | query = Query() , |
|||
int | nToReturn = 0 , |
|||
int | nToSkip = 0 , |
|||
const BSONObj * | fieldsToReturn = 0 , |
|||
int | queryOptions = 0 , |
|||
int | batchSize = 0 | |||
) | [inline, virtual] |
send a query to the database.
ns | namespace to query, format is <dbname>.<collectname>[.<collectname>]* | |
query | query to perform on the collection. this is a BSONObj (binary JSON) You may format as { query: { ... }, orderby: { ... } } to specify a sort order. | |
nToReturn | n to return (i.e., limit). 0 = unlimited | |
nToSkip | start with the nth item | |
fieldsToReturn | optional template of which fields to select. if unspecified, returns all fields | |
queryOptions | see options enum at top of this file |
AssertionException |
Reimplemented from mongo::DBClientBase.
Definition at line 840 of file dbclient.h.
virtual void mongo::DBClientConnection::recv | ( | Message & | m | ) | [protected, virtual] |
Reimplemented from mongo::DBConnector.
virtual void mongo::DBClientConnection::say | ( | Message & | toSend | ) | [virtual] |
Implements mongo::DBClientBase.
virtual void mongo::DBClientConnection::sayPiggyBack | ( | Message & | toSend | ) | [protected, virtual] |
Implements mongo::DBConnector.
static void mongo::DBClientConnection::setLazyKillCursor | ( | bool | lazy | ) | [inline, static] |
Definition at line 887 of file dbclient.h.
void mongo::DBClientConnection::setSoTimeout | ( | double | to | ) | [inline] |
Definition at line 881 of file dbclient.h.
string mongo::DBClientConnection::toString | ( | ) | [inline, virtual] |
Returns the address of the server
Implements mongo::DBClientWithCommands.
Definition at line 871 of file dbclient.h.
string mongo::DBClientConnection::toStringLong | ( | ) | const [inline] |
Definition at line 863 of file dbclient.h.
virtual ConnectionString::ConnectionType mongo::DBClientConnection::type | ( | ) | const [inline, virtual] |
Implements mongo::DBClientBase.
Definition at line 879 of file dbclient.h.
friend class SyncClusterConnection [friend] |
Definition at line 891 of file dbclient.h.
bool mongo::DBClientConnection::_lazyKillCursor [static, protected] |
Definition at line 913 of file dbclient.h.
AtomicUInt mongo::DBClientConnection::_numConnections [static, protected] |
Definition at line 912 of file dbclient.h.
HostAndPort mongo::DBClientConnection::_server [protected] |
Definition at line 901 of file dbclient.h.
string mongo::DBClientConnection::_serverString [protected] |
Definition at line 902 of file dbclient.h.
double mongo::DBClientConnection::_so_timeout [protected] |
Definition at line 909 of file dbclient.h.
map< string, pair<string,string> > mongo::DBClientConnection::authCache [protected] |
Definition at line 908 of file dbclient.h.
const bool mongo::DBClientConnection::autoReconnect [protected] |
Definition at line 899 of file dbclient.h.
DBClientReplicaSet* mongo::DBClientConnection::clientSet [protected] |
Definition at line 895 of file dbclient.h.
bool mongo::DBClientConnection::failed [protected] |
Definition at line 898 of file dbclient.h.
time_t mongo::DBClientConnection::lastReconnectTry [protected] |
Definition at line 900 of file dbclient.h.
boost::scoped_ptr<MessagingPort> mongo::DBClientConnection::p [protected] |
Definition at line 896 of file dbclient.h.
boost::scoped_ptr<SockAddr> mongo::DBClientConnection::server [protected] |
Definition at line 897 of file dbclient.h.