7.2 KiB
Cursor ⇐ Promise
Manage access to data, be it to find, update or remove it.
It extends Promise
so that its methods (which return this
) are chainable & awaitable.
Kind: global class
Extends: Promise
- Cursor ⇐
Promise
- new Cursor(db, query, [execFn], [hasCallback])
- instance
- .db :
Datastore
- .query :
query
- .hasCallback :
boolean
- .limit(limit) ⇒
Cursor
- .skip(skip) ⇒
Cursor
- .sort(sortQuery) ⇒
Cursor
- .projection(projection) ⇒
Cursor
- .project(candidates) ⇒
Array.<document>
- ._execAsync() ⇒
Array.<document>
|Promise.<*>
- ._exec(_callback)
- .exec(_callback)
- .execAsync() ⇒
Promise.<(Array.<document>|*)>
- .db :
- inner
- ~execFnWithCallback :
function
- ~execFnWithoutCallback ⇒
Promise
|*
- ~execCallback :
function
- ~execFnWithCallback :
new Cursor(db, query, [execFn], [hasCallback])
Create a new cursor for this collection
Params
- db
Datastore
-The datastore this cursor is bound to
- query
query
-The query this cursor will operate on
- [execFn]
execFnWithoutCallback
|execFnWithCallback
-Handler to be executed after cursor has found the results and before the callback passed to find/findOne/update/remove
- [hasCallback]
boolean
= true
-If false, specifies that the
execFn
is of type execFnWithoutCallback rather than execFnWithCallback.
cursor.db : Datastore
Kind: instance property of Cursor
Access: protected
cursor.query : query
Kind: instance property of Cursor
Access: protected
cursor.hasCallback : boolean
Determines if the [Cursor#execFn](Cursor#execFn) is an [execFnWithoutCallback](#Cursor..execFnWithoutCallback) or not.
Kind: instance property of Cursor
Access: protected
cursor.limit(limit) ⇒ Cursor
Set a limit to the number of results
Kind: instance method of Cursor
Params
- limit
Number
cursor.skip(skip) ⇒ Cursor
Skip a number of results
Kind: instance method of Cursor
Params
- skip
Number
cursor.sort(sortQuery) ⇒ Cursor
Sort results of the query
Kind: instance method of Cursor
Params
- sortQuery
Object.<string, number>
-sortQuery is { field: order }, field can use the dot-notation, order is 1 for ascending and -1 for descending
cursor.projection(projection) ⇒ Cursor
Add the use of a projection
Kind: instance method of Cursor
Params
- projection
Object.<string, number>
-MongoDB-style projection. {} means take all fields. Then it's { key1: 1, key2: 1 } to take only key1 and key2 { key1: 0, key2: 0 } to omit only key1 and key2. Except _id, you can't mix takes and omits.
cursor.project(candidates) ⇒ Array.<document>
Apply the projection.
This is an internal function. You should use [execAsync](#Cursor+execAsync) or [exec](#Cursor+exec).
Kind: instance method of Cursor
Access: protected
Params
- candidates
Array.<document>
cursor._execAsync() ⇒ Array.<document>
| Promise.<*>
Get all matching elements Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne This is an internal function, use execAsync which uses the executor
Kind: instance method of Cursor
cursor._exec(_callback)
Get all matching elements Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne
This is an internal function, use [exec](#Cursor+exec) which uses the [executor](#Datastore+executor).
Kind: instance method of Cursor
Access: protected
See: Cursor#exec
Params
- _callback
execCallback
cursor.exec(_callback)
Get all matching elements Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne
Kind: instance method of Cursor
Params
- _callback
execCallback
cursor.execAsync() ⇒ Promise.<(Array.<document>|*)>
Async version of [exec](#Cursor+exec).
Kind: instance method of Cursor
See: Cursor#exec
Cursor~execFnWithCallback : function
Has a callback
Kind: inner typedef of Cursor
Params
- err
Error
- res
?Array.<document>
|document
Cursor~execFnWithoutCallback ⇒ Promise
| *
Does not have a callback, may return a Promise.
Kind: inner typedef of Cursor
Params
- res
?Array.<document>
|document
Cursor~execCallback : function
Kind: inner typedef of Cursor
Params
- err
Error
- res
Array.<document>
|*
-If an execFn was given to the Cursor, then the type of this parameter is the one returned by the execFn.