Qore mongodb Module 2.3.0
Loading...
Searching...
No Matches
mongodb::MongoCursor Class Reference

The MongoCursor class provides iteration over MongoDB query results. More...

#include <QC_MongoCursor.dox.h>

Public Member Methods

nothing close ()
 Closes the cursor and releases resources.
 
bool more ()
 Checks if there are more documents available.
 
*hash< auto > next ()
 Returns the next document from the cursor.
 
list< hash< auto > > toList ()
 Returns all remaining documents as a list.
 

Detailed Description

The MongoCursor class provides iteration over MongoDB query results.

This class is returned by find() and aggregate() operations and allows iterating over the result documents one at a time.

Example:
# Iterate using next()
MongoCursor cursor = coll.find({"status": "active"});
while (*hash<auto> doc = cursor.next()) {
printf("Document: %y\n", doc);
}
# Get all results as a list
MongoCursor cursor = coll.find();
list<hash<auto>> docs = cursor.toList();
Since
mongodb 1.0

Member Function Documentation

◆ close()

nothing mongodb::MongoCursor::close ( )

Closes the cursor and releases resources.

Example:
cursor.close();
Note
Cursors are automatically closed when garbage collected, but calling close() explicitly is recommended for long-lived cursor objects.

◆ more()

bool mongodb::MongoCursor::more ( )

Checks if there are more documents available.

Returns
True if there are more documents
Example:
while (cursor.more()) {
hash<auto> doc = cursor.next();
// process doc
}
Note
This method may not be 100% accurate for all cursor types. It's generally better to use next() and check for nothing.

◆ next()

*hash< auto > mongodb::MongoCursor::next ( )

Returns the next document from the cursor.

Returns
the next document, or nothing if no more documents
Example:
while (*hash<auto> doc = cursor.next()) {
printf("Document: %y\n", doc);
}
Exceptions
MONGODB-CURSOR-ERRORcursor error

◆ toList()

list< hash< auto > > mongodb::MongoCursor::toList ( )

Returns all remaining documents as a list.

Returns
a list of all remaining documents
Example:
list<hash<auto>> docs = cursor.toList();
foreach hash<auto> doc in (docs) {
printf("Document: %y\n", doc);
}
Exceptions
MONGODB-CURSOR-ERRORcursor error
Note
This method exhausts the cursor. After calling toList(), subsequent calls to next() will return nothing.

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