classafMongo::Cursor

sys::Obj
  afMongo::Cursor

Iterates over database query results.

@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 not affected by skip or limit.

explain

Source

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

Source

Str[]? fieldNames

The names of the fields to be returned in the query results.

Leave as null to return all fields.

This value can not be changed once the query has been sent to the server.

flags

Source

Flag flags

Optional flags to set in the query.

This value can not be changed once the query has been sent to the server.

@see OpQueryFlags

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 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 sort the query results in ascending or descending order.

If sort is a [Str:Obj?] map, it should be a sort 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/

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