MongoCursor Class
MongoCursor
Constructor
MongoCursor
-
collection
-
cur
Parameters:
-
collection
MongoCollectionThe collection to work with
-
cur
ObjectCursor
Item Index
Methods
batchSize
-
n
Specify the number of documents to return in each batch of the response from the MongoDB instance.
Parameters:
-
n
Numberthe number of elements to return in a batch
Returns:
close
()
Kills the current cursor on the server.
count
()
Number
Counts the number of objects matching the query This does not take limit/skip into consideration
Returns:
curr
()
MongoDocument
Returns the element the cursor is at.
Returns:
explain
()
Object
Provides information on the query plan. The query plan is the plan the server uses to find the matches for a query. This information may be useful when optimizing a query
See official documentation for more information
Returns:
forEach
-
fn
Iterate trough cursor with a function.
Parameters:
-
fn
Functionthe function to execute for each result item
Returns:
hasNext
()
Boolean
Checks if there is another object available
Returns:
limit
-
n
Limits the number of elements returned.
Parameters:
-
n
Numberthe number of elements to return (should be positive)
Returns:
next
()
MongoDocument
Returns the object the cursor is at and moves the cursor ahead by one.
Returns:
size
()
Number
Counts the number of objects matching the query this does take limit/skip into consideration
Returns:
skip
-
n
Discards a given number of elements at the beginning of the cursor.
Parameters:
-
n
Numberthe number of elements to skip
Returns:
snapshot
()
MongoCursor
chainable
Toggle cursor to the snapshot
mode. This ensures that the query
will not return a document multiple times, even if intervening write
operations result in a move of the document due to the growth in
document size. Currently, snapshot mode may not be used with sorting
or explicit hints.
Returns:
toArray
-
max
Converts this cursor to an array.
There are 2 modes for the cursors, iterator and array. If you use next() or hasNext(), then you can't call toArray
Parameters:
-
max
Numberthe maximum number of objects to return