API Docs for:
Show:

MongoCursor Class

Module: ringo-mongodb

MongoCursor

Constructor

MongoCursor

(
  • collection
  • cur
)

Parameters:

Methods

batchSize

(
  • n
)
MongoCursor chainable

Specify the number of documents to return in each batch of the response from the MongoDB instance.

Parameters:

  • n Number

    the number of elements to return in a batch

Returns:

MongoCursor: a cursor to iterate over results

close

()

Kills the current cursor on the server.

count

() Number

Counts the number of objects matching the query This does not take limit/skip into consideration

Returns:

Number: the number of objects

curr

() MongoDocument

Returns the element the cursor is at.

Returns:

MongoDocument: the current element

explain

() Object

Provides information on the query plan. The query plan is the plan the server uses to find the matches for a query. This information may be useful when optimizing a query

See official documentation for more information

Returns:

Object: A document that describes the process used to return the query results

forEach

(
  • fn
)
Object

Iterate trough cursor with a function.

Parameters:

  • fn Function

    the function to execute for each result item

Returns:

Object: A document that describes the process used to return the query results

hasNext

() Boolean

Checks if there is another object available

Returns:

Boolean: returns true if another object is available, false otherwise

limit

(
  • n
)
MongoCursor chainable

Limits the number of elements returned.

Parameters:

  • n Number

    the number of elements to return (should be positive)

Returns:

MongoCursor: a cursor to iterate over results

next

() MongoDocument

Returns the object the cursor is at and moves the cursor ahead by one.

Returns:

MongoDocument: the next element

size

() Number

Counts the number of objects matching the query this does take limit/skip into consideration

Returns:

Number: the number of objects

skip

(
  • n
)
MongoCursor chainable

Discards a given number of elements at the beginning of the cursor.

Parameters:

  • n Number

    the number of elements to skip

Returns:

MongoCursor: a cursor pointing to the new first element of the results

snapshot

() MongoCursor chainable

Toggle cursor to the snapshot mode. This ensures that the query will not return a document multiple times, even if intervening write operations result in a move of the document due to the growth in document size. Currently, snapshot mode may not be used with sorting or explicit hints.

Returns:

MongoCursor: same DBCursor for chaining operations

toArray

(
  • max
)
Array

Converts this cursor to an array.

There are 2 modes for the cursors, iterator and array. If you use next() or hasNext(), then you can't call toArray

Parameters:

  • max Number

    the maximum number of objects to return

Returns:

Array: an array of MongoDocument