vibe.db.mongo.cursor

MongoDB cursor abstraction

Types 6

structMongoCursor(DocType = Bson)

Represents a cursor for a MongoDB query.

Use foreach( doc; cursor ) to iterate over the list of documents.

This struct uses reference counting to destroy the underlying MongoDB cursor.

Fields
private IMongoCursorData!DocType m_data
Methods
bool empty() @propertyReturns true if there are no more documents for this cursor.
DocType front() @propertyReturns the current document of the response.
MongoCursor sort(T)(T order)Controls the order in which the query returns matching documents.
MongoCursor limit(long count)Limits the number of documents that the cursor returns.
MongoCursor skip(long count)Skips a given number of elements at the beginning of the cursor.
void popFront()Advances the cursor to the next document of the response.
auto byPair()Iterates over all remaining documents.
Constructors
this(MongoClient client, string collection, QueryFlags flags, int nskip, int nret, Q query, S return_field_selector)
this(MongoClient client, string collection, long cursor, DocType[] existing_documents)
this(MongoClient client, string database, string collection, Q query, FindOptions options)
this(MongoClient client, Bson command, int batchSize = 0, Duration getMoreMaxTime = Duration.max)
Destructors
private interfaceIMongoCursorData(DocType)

Actual iteration implementation details for MongoCursor. Abstracted using an interface because we still have code for legacy (<3.6) MongoDB servers, which may still used with the old legacy overloads.

Methods
bool alive() @property @safe nothrow;
bool empty() @safe
long index() @safe
DocType front() @safe
void popFront() @safe
void sort(Bson order) @safeBefore iterating, specify a MongoDB sort order
void limit(long count) @safeBefore iterating, specify maximum number of returned items
void skip(long count) @safeBefore iterating, skip the specified number of items (when sorted)
void killCursors() @safeKills the MongoDB cursor, further iteration attempts will result in errors. Call this in the destructor.
int refCount() ref @safeDefine an reference count property on the class, which is returned by reference with this method.
private classLegacyMongoCursorData(DocType) : IMongoCursorData!DocType
deprecated

Deprecated query internals exposed through MongoCursor.

Fields
int m_refCount
MongoClient m_client
string m_collection
long m_cursor
long m_nskip
int m_nret
Bson m_sort
int m_offset
size_t m_currentDoc
DocType[] m_documents
bool m_iterationStarted
long m_limit
Methods
bool alive() @property @safe nothrow
bool empty() @safe
long index() @safe
DocType front() @safe
void sort(Bson order) @safe
void limit(long count) @safe
void skip(long count) @safe
void popFront() @safe
void startIterating() @safe
void killCursors() @safe
void handleReply(long cursor, ReplyFlags flags, int first_doc, int num_docs)
void handleDocument(size_t idx, ref DocType doc)
int refCount() ref
private classMongoFindCursor(DocType) : IMongoCursorData!DocType

Find + getMore internals exposed through MongoCursor. Unifies the old LegacyMongoCursorData approach, so it can be used both for find queries and for custom commands.

Fields
int m_refCount
MongoClient m_client
Bson m_findQuery
string m_database
string m_ns
string m_collection
long m_cursor
int m_batchSize
Duration m_maxTime
long m_totalReceived
size_t m_readDoc
size_t m_insertDoc
DocType[] m_documents
bool m_iterationStarted
long m_queryLimit
Methods
bool alive() @property @safe nothrow
bool empty() @safe
long index() @safe
DocType front() @safe
void sort(Bson order) @safe
void limit(long count) @safe
void skip(long count) @safe
void popFront() @safe
private void startIterating() @safe
void killCursors() @safe
void handleReply(long id, string ns, size_t count)
void handleDocument(ref DocType doc)
int refCount() ref
Constructors
this(MongoClient client, Bson command, int batchSize = 0, Duration getMoreMaxTime = Duration.max)
private classMongoQueryCursor(Q, R, S) : LegacyMongoCursorData!R
deprecated

Internal class implementing MongoCursorData for find queries

Fields
QueryFlags m_flags
Q m_query
S m_returnFieldSelector
Methods
void startIterating() @safe
Constructors
this(MongoClient client, string collection, QueryFlags flags, int nskip, int nret, Q query, S return_field_selector)
private classMongoGenericCursor(DocType) : LegacyMongoCursorData!DocType
deprecated

Internal class implementing MongoCursorData for already initialized generic cursors

Methods
void startIterating() @safe
Constructors
this(MongoClient client, string collection, long cursor, DocType[] existing_documents)