MongoDB  1.8.5
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends
mongo::DBClientConnection Class Reference

A basic connection to the database. More...

#include <dbclient.h>

Inheritance diagram for mongo::DBClientConnection:
mongo::DBClientBase mongo::DBClientWithCommands mongo::DBConnector mongo::DBClientInterface

List of all members.

Public Member Functions

 DBClientConnection (bool _autoReconnect=false, DBClientReplicaSet *cp=0, double so_timeout=0)
virtual bool connect (const char *hostname, string &errmsg)
 Connect to a Mongo database server.
virtual bool connect (const HostAndPort &server, string &errmsg)
 Connect to a Mongo database server.
void connect (const string &serverHostname)
 Connect to a Mongo database server.
virtual bool auth (const string &dbname, const string &username, const string &pwd, string &errmsg, bool digestPassword=true)
 Authorize access to a particular database.
virtual auto_ptr< DBClientCursorquery (const string &ns, Query query=Query(), int nToReturn=0, int nToSkip=0, const BSONObj *fieldsToReturn=0, int queryOptions=0, int batchSize=0)
 send a query to the database.
unsigned long long 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.
unsigned long long query (boost::function< void(DBClientCursorBatchIterator &)> f, const string &ns, Query query, const BSONObj *fieldsToReturn=0, int queryOptions=0)
bool isFailed () const
MessagingPortport ()
string toStringLong () const
string toString ()
 Returns the address of the server.
string getServerAddress () const
virtual void killCursor (long long cursorID)
virtual bool callRead (Message &toSend, Message &response)
virtual void say (Message &toSend)
virtual bool call (Message &toSend, Message &response, bool assertOk=true, string *actualServer=0)
 actualServer is set to the actual server where they call went if there was a choice (SlaveOk)
virtual
ConnectionString::ConnectionType 
type () const
virtual void checkResponse (const char *data, int nReturned)
void setSoTimeout (double to)

Static Public Member Functions

static int getNumConnections ()
static void setLazyKillCursor (bool lazy)
static bool getLazyKillCursor ()

Protected Member Functions

virtual void recv (Message &m)
virtual void sayPiggyBack (Message &toSend)
void _checkConnection ()
void checkConnection ()
bool _connect (string &errmsg)

Protected Attributes

DBClientReplicaSetclientSet
boost::scoped_ptr< MessagingPortp
boost::scoped_ptr< SockAddrserver
bool failed
const bool autoReconnect
time_t lastReconnectTry
HostAndPort _server
string _serverString
map< string, pair< string,
string > > 
authCache
double _so_timeout

Static Protected Attributes

static AtomicUInt _numConnections
static bool _lazyKillCursor = true

Friends

class SyncClusterConnection

Detailed Description

A basic connection to the database.

This is the main entry point for talking to a simple Mongo setup


Constructor & Destructor Documentation

mongo::DBClientConnection::DBClientConnection ( bool  _autoReconnect = false,
DBClientReplicaSet cp = 0,
double  so_timeout = 0 
) [inline]
Parameters:
_autoReconnectif true, automatically reconnect on a connection failure
cpused by DBClientReplicaSet. You do not need to specify this parameter
timeouttcp timeout in seconds - this is for read/write, not connect. Connect timeout is fixed, but short, at 5 seconds.

Member Function Documentation

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.

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

Reimplemented from mongo::DBClientWithCommands.

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.

Parameters:
serverHostnamehost 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 )
errmsgany relevant error message will appended to the string
Deprecated:
please use HostAndPort
Returns:
false if fails to connect.
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.

Parameters:
serverserver to connect to.
errmsgany relevant error message will appended to the string
Returns:
false if fails to connect.
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.

Parameters:
serverHostnamehost to connect to. can include port number ( 127.0.0.1 , 127.0.0.1:5555 )
bool mongo::DBClientConnection::isFailed ( ) const [inline, virtual]
Returns:
true if this connection is currently in a failed state. When autoreconnect is on, a connection will transition back to an ok state after reconnecting.

Implements mongo::DBClientBase.

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.

Parameters:
nsnamespace to query, format is <dbname>.<collectname>[.<collectname>]*
queryquery to perform on the collection. this is a BSONObj (binary JSON) You may format as { query: { ... }, orderby: { ... } } to specify a sort order.
nToReturnn to return (i.e., limit). 0 = unlimited
nToSkipstart with the nth item
fieldsToReturnoptional template of which fields to select. if unspecified, returns all fields
queryOptionssee options enum at top of this file
Returns:
cursor. 0 if error (connection failure)
Exceptions:
AssertionException

Reimplemented from mongo::DBClientBase.

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.


The documentation for this class was generated from the following files: