classafMongo::Cursor
sys::Obj afMongo::Cursor
Iterates over database query results. See Collection.find().
- 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 affected byskiporlimit.@see http://docs.mongodb.org/manual/reference/command/count/
- flags
OpQueryFlags flagsOptional flags to set in the query.
This value can not be changed once the query has been sent to the server.
- 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
// --> 10cursor.skip = 2 cursor.index// --> 2cursor.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
nullor set to zero to 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 order the query results in ascending or descending order.
If
orderByis a[Str:Obj?]map, it should be a 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/
- projection
Use to alter / set which fields returned in the Mongo responses.
Set field names with a value of
1to limit returned fields to just those mentioned. Example:cursor.projection = [ "fieldName1" : 1, "fieldName2" : 1 ]Would limit the returned fields to just
_id,fieldName1, &fieldName2.Leave as
nullto return all fields.See Projection Operators for other uses.
This value can not be changed once the query has been sent to the server.
- 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
// --> 10cursor.skip = 2 cursor.next cursor.next list := cursor.toList list.size// --> 6