23#include "mongo/client/export_macros.h"
25#include "mongo/db/json.h"
26#include "mongo/util/net/message.h"
30 class DBClientCursorShim;
31 class DBClientCursorShimCursorID;
32 class DBClientCursorShimArray;
33 class DBClientCursorShimTransform;
41 virtual bool more() = 0;
59 int objsLeftInBatch()
const { _assertIfNull();
return _putBack.size() + batch.nReturned - batch.pos; }
60 bool moreInCurrentBatch() {
return objsLeftInBatch() > 0; }
86 void peek(std::vector<BSONObj>&,
int atMost);
113 bool isDead()
const {
return cursorId == 0; }
123 return (resultFlags & flag) != 0;
130 int _nToSkip,
const BSONObj *_fieldsToReturn,
int queryOptions ,
int bs );
131 DBClientCursor(
DBClientBase* client,
const std::string &_ns,
long long _cursorId,
int _nToReturn,
int options,
int _batchSize );
135 long long getCursorId()
const {
return cursorId; }
142 std::string originalHost()
const {
return _originalHost; }
144 std::string getns()
const {
return ns; }
146 Message* getMessage(){
return batch.m.get(); }
163 void initLazy(
bool isRetry =
false );
164 bool initLazyFinish(
bool& retry );
168 std::auto_ptr<Message> m;
173 Batch() : m(
new Message() ), nReturned(), pos(), data() { }
185 void _finishConsInit();
190 std::auto_ptr<DBClientCursorShim> shim;
194 std::string _originalHost;
203 std::stack< BSONObj > _putBack;
207 std::string _scopedHost;
208 std::string _lazyHost;
211 void dataReceived() {
bool retry; std::string lazyHost; dataReceived( retry, lazyHost ); }
212 void dataReceived(
bool& retry, std::string& lazyHost );
214 void exhaustReceiveMore();
217 void _assertIfNull()
const { uassert(13348,
"connection died",
this); }
220 DBClientCursor(
const DBClientCursor& );
221 DBClientCursor& operator=(
const DBClientCursor& );
224 void _assembleInit( Message& toSend );
232 bool moreInCurrentBatch() {
return _c.moreInCurrentBatch(); }
234 massert( 13383,
"BatchIterator empty", moreInCurrentBatch() );
236 return _c.nextSafe();
238 int n()
const {
return _n; }
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representa...
Definition bsonobj.h:78
BSONObj getOwned() const
assure the data buffer is under the control of this BSONObj and not a remote buffer
abstract class that implements the core db operations
Definition dbclientinterface.h:1330
A basic connection to the database.
Definition dbclientinterface.h:1551
iterate over objects in current batch only - will not cause a network call
Definition dbclientcursor.h:229
for mock purposes only – do not create variants of DBClientCursor, nor hang code here
Definition dbclientcursor.h:38
DBClientCursorShimArray implements the shim interface over an array of bson obj's.
Definition dbclientcursorshimarray.h:28
DBClientCursorShimCursorID implements the shim interface over a cursor reply document,...
Definition dbclientcursorshimcursorid.h:29
Definition dbclientcursor.h:166
Queries return a cursor object.
Definition dbclientcursor.h:49
bool more()
If true, safe to call next().
void setBatchSize(int newBatchSize)
Change batchSize after construction. Can change after requesting first batch.
Definition dbclientcursor.h:127
bool init()
actually does the query
bool hasResultFlag(int flag)
see ResultFlagType (constants.h) for flag values mostly these flags are for internal purposes - Resul...
Definition dbclientcursor.h:121
bool isDead() const
cursor no longer valid – use with tailable cursors.
Definition dbclientcursor.h:113
int itcount()
iterate the rest of the cursor and return the number if items
Definition dbclientcursor.h:99
int objsLeftInBatch() const
If true, there is more in our local buffers to be fetched via next().
Definition dbclientcursor.h:59
bool initCommand()
Used mainly to run commands on connections that doesn't support lazy initialization and does not supp...
BSONObj nextSafe()
throws AssertionException if get back { $err : ... }
void decouple()
by default we "own" the cursor and will send the server a KillCursor message when ~DBClientCursor() i...
Definition dbclientcursor.h:140
bool peekError(BSONObj *error=NULL)
peek ahead and see if an error occurred, and get the error if so.
void putBack(const BSONObj &o)
restore an object previously returned by next() to the cursor
Definition dbclientcursor.h:76
void peek(std::vector< BSONObj > &, int atMost)
peek ahead at items buffered for future next() calls.
DB "commands" Basically just invocations of connection.
Definition dbclientinterface.h:662
Core MongoDB C++ driver interfaces are defined here.
QueryOption_CursorTailable
Tailable means cursor is not closed when the last data is retrieved.
Definition dbclientinterface.h:55
the main MongoDB namespace
Definition bulk_operation_builder.h:24