MongoDB C++ Driver  legacy-1.1.2
Classes | Public Member Functions | List of all members
mongo::DBClientCursor Class Reference

Queries return a cursor object. More...

#include <dbclientcursor.h>

+ Inheritance diagram for mongo::DBClientCursor:

Classes

class  Batch
 

Public Member Functions

bool more ()
 If true, safe to call next(). More...
 
int objsLeftInBatch () const
 If true, there is more in our local buffers to be fetched via next(). More...
 
BSONObj next ()
 next More...
 
void putBack (const BSONObj &o)
 restore an object previously returned by next() to the cursor
 
BSONObj nextSafe ()
 throws AssertionException if get back { $err : ... More...
 
void peek (std::vector< BSONObj > &, int atMost)
 peek ahead at items buffered for future next() calls. More...
 
bool peekError (BSONObj *error=NULL)
 peek ahead and see if an error occurred, and get the error if so.
 
int itcount ()
 iterate the rest of the cursor and return the number if items
 
bool isDead () const
 cursor no longer valid – use with tailable cursors. More...
 
bool hasResultFlag (int flag)
 see ResultFlagType (constants.h) for flag values mostly these flags are for internal purposes - ResultFlag_ErrSet is the possible exception to that
 
void setBatchSize (int newBatchSize)
 Change batchSize after construction. Can change after requesting first batch.
 
void decouple ()
 by default we "own" the cursor and will send the server a KillCursor message when ~DBClientCursor() is called. More...
 
bool initCommand ()
 Used mainly to run commands on connections that doesn't support lazy initialization and does not support commands through the call interface. More...
 
bool init ()
 actually does the query
 
void kill ()
 Marks this object as dead and sends the KillCursors message to the server. More...
 

Detailed Description

Queries return a cursor object.

Member Function Documentation

void mongo::DBClientCursor::decouple ( )
inline

by default we "own" the cursor and will send the server a KillCursor message when ~DBClientCursor() is called.

This function overrides that.

bool mongo::DBClientCursor::initCommand ( )

Used mainly to run commands on connections that doesn't support lazy initialization and does not support commands through the call interface.

Parameters
cmdThe BSON representation of the command to send.
Returns
true if command was sent successfully
bool mongo::DBClientCursor::isDead ( ) const
inline

cursor no longer valid – use with tailable cursors.

note you should only rely on this once more() returns false; 'dead' may be preset yet some data still queued and locally available from the dbclientcursor.

void mongo::DBClientCursor::kill ( )

Marks this object as dead and sends the KillCursors message to the server.

Any errors that result from this are swallowed since this is typically performed as part of cleanup and a failure to kill the cursor should not result in a failure of the operation using the cursor.

Killing an already killed or exhausted cursor does nothing, so it is safe to always call this if you want to ensure that a cursor is killed.

bool mongo::DBClientCursor::more ( )
virtual

If true, safe to call next().

Requests more from server if necessary.

Implements mongo::DBClientCursorInterface.

BSONObj mongo::DBClientCursor::next ( )
virtual

next

Returns
next object in the result cursor. on an error at the remote server, you will get back: { $err: <string> } if you do not want to handle that yourself, call nextSafe().

Warning: The returned BSONObj will become invalid after the next batch is fetched or when this cursor is destroyed.

Implements mongo::DBClientCursorInterface.

BSONObj mongo::DBClientCursor::nextSafe ( )

throws AssertionException if get back { $err : ...

}

int mongo::DBClientCursor::objsLeftInBatch ( ) const
inline

If true, there is more in our local buffers to be fetched via next().

Returns false when a getMore request back to server would be required. You can use this if you want to exhaust whatever data has been fetched to the client already but then perhaps stop.

void mongo::DBClientCursor::peek ( std::vector< BSONObj > &  ,
int  atMost 
)

peek ahead at items buffered for future next() calls.

never requests new data from the server. so peek only effective with what is already buffered. WARNING: no support for _putBack yet!


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