classafMongo::Cursor
sys::Obj afMongo::Cursor
Iterates over database query results.
- ASC
const static Int ASC := 1Use in
orderBymaps to denote sort order.- DESC
const static Int DESC := -1Use in
orderBymaps to denote sort order.- batchSize
Int? batchSizeThe number of documents to be returned in each response from the server.
Leave as
nullto use the default size.This value can not be changed once a query has been sent to the server.
- count
Int count()Returns the maximum number of documents this query can return.
countis constant for any given query and is not affected byskiporlimit.- explain
Returns a query plan that describes the process and indexes used to return the query. Useful when attempting to optimise queries.
@see http://docs.mongodb.org/manual/reference/operator/meta/explain/
- fieldNames
Str[]? fieldNamesThe names of the fields to be returned in the query results.
Leave as
nullto return all fields.This value can not be changed once the query has been sent to the server.
- flags
Flag flagsOptional flags to set in the query.
This value can not be changed once the query has been sent to the server.
@see OpQueryFlags
- hasNext
Bool hasNext()Are more documents to be returned? Use with
next()to iterate over the results:while (cursor.hasNext) { doc := cursor.next ... }- hint
Str? hintThe name of the index to use for sorting.
This value can not be changed once the query has been sent to the server.
@see http://docs.mongodb.org/manual/reference/operator/meta/hint/
- index
Int index { private set }A zero based index into the documents returned by the query.
cursor.count // --> 10 cursor.skip = 2 cursor.index // --> 2 cursor.next cursor.index // --> 3
- isAlive
Bool isAlive()Returns
trueif the cursor is alive on the server.Note this returns
falseif a query has not yet been sent to the server.- limit
Int? limitThe maximum number of documents this cursor will read.
Leave as
nullto read all results from the query.This value can not be changed once a query has been sent to the server.
- next
[Str:Obj?]? next(Bool checked := true)Returns the next document from the query. Use with
hasNext()to iterate over the results:while (cursor.hasNext) { doc := cursor.next ... }If
checkedistrueand there are no more results to return then anMongoCursorErris thrown, elsenullis returned.- orderBy
Use to sort the query results in ascending or descending order.
If
sortis a[Str:Obj?]map, it should be a sort document with field names as keys. Values may either be the standard Mongo1and-1for ascending / descending or the stringsASC/DESC. ShouldorderBycontain more than 1 entry, it must be ordered.Examples:
cursor.orderBy = ["age": 1] cursor.orderBy = [:] { ordered = true }.add("name", "asc").add("age", "desc")This value can not be changed once the query has been sent to the server.
@see http://docs.mongodb.org/manual/reference/operator/meta/orderby/
- query
Str:Obj? query { private set }The query as used by this cursor.
- skip
Int skipThe number of documents to omit, when returning the result of the query.
Leave as
0to return all documents.This value can not be changed once the query has been sent to the server.
- special
Query modifiers to use. Synonymous to using
_addSpecial()in the mongo shell.This value can not be changed once the query has been sent to the server.
@see http://docs.mongodb.org/manual/reference/operator/query-modifier/
- toList
Return all remaining and unread documents as a List.
cursor.count // --> 10 cursor.skip = 2 cursor.next cursor.next list := cursor.toList list.size // --> 6