classafMongo::Cursor

sys::Obj
  afMongo::Cursor

Iterates over database query results. See Collection.find().

@see http://docs.mongodb.org/manual/core/cursors/

ASC

Source

const static Int ASC := 1

Use in orderBy maps to denote sort order.

DESC

Source

const static Int DESC := -1

Use in orderBy maps to denote sort order.

batchSize

Source

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

Source

Int count()

Returns the maximum number of documents this query can return. count is constant for any given query and is affected by skip or limit.

@see http://docs.mongodb.org/manual/reference/command/count/

flags

Source

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

Source

Bool hasNext()

Are more documents to be returned? Use with next() to iterate over the results:

while (cursor.hasNext) {
    doc := cursor.next
    ...
}
hint

Source

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

Source

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

Source

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

Source

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.

Source

[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 is true and there are no more results to return then an MongoCursorErr is thrown, else null is returned.

orderBy

Source

[Str:Obj?]? 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 Mongo 1 and -1 for ascending / descending or the strings ASC / DESC. Should orderBy 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

Source

[Str:Obj?]? 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

Source

Str:Obj? query { private set }

The query as used by this cursor.

Source

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

Source

Str:Obj? 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

Source

Str:Obj?[] 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