classafMongo::Cursor
sys::Obj afMongo::Cursor
Iterates over database query results. See Collection.find().
- ASC
const static Int ASC := 1
Use in
orderBy
maps to denote sort order.- DESC
const static Int DESC := -1
Use in
orderBy
maps to denote sort order.- batchSize
Int? batchSize
The number of documents to be returned in each response from the server.
Leave as
null
to 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.
count
is constant for any given query and is affected byskip
orlimit
.@see http://docs.mongodb.org/manual/reference/command/count/
- flags
OpQueryFlags flags
Optional 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? hint
The 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
true
if the cursor is alive on the server.Note this returns
false
if a query has not yet been sent to the server.- limit
Int? limit
The maximum number of documents this cursor will read.
Leave as
null
or 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
checked
istrue
and there are no more results to return then anMongoCursorErr
is thrown, elsenull
is returned.- orderBy
Use to order the query results in ascending or descending order.
If
orderBy
is a[Str:Obj?]
map, it should be a document with field names as keys. Values may either be the standard Mongo1
and-1
for ascending / descending or the stringsASC
/DESC
. ShouldorderBy
contain 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
1
to 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
null
to 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 skip
The number of documents to omit, when returning the result of the query.
Leave as
0
to 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