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.
Promise
* [Cursor](#Cursor) ⇐ Promise
* [new Cursor(db, query, [execFn], [hasCallback])](#new_Cursor_new)
* _instance_
* [.db](#Cursor+db) : [Datastore
](#Datastore)
* [.query](#Cursor+query) : [query
](#query)
* [.hasCallback](#Cursor+hasCallback) : boolean
* [.limit(limit)](#Cursor+limit) ⇒ [Cursor
](#Cursor)
* [.skip(skip)](#Cursor+skip) ⇒ [Cursor
](#Cursor)
* [.sort(sortQuery)](#Cursor+sort) ⇒ [Cursor
](#Cursor)
* [.projection(projection)](#Cursor+projection) ⇒ [Cursor
](#Cursor)
* [.project(candidates)](#Cursor+project) ⇒ [Array.<document>
](#document)
* [._execAsync()](#Cursor+_execAsync) ⇒ [Array.<document>
](#document) \| Promise.<\*>
* [._exec(_callback)](#Cursor+_exec)
* [.exec(_callback)](#Cursor+exec)
* [.execAsync()](#Cursor+execAsync) ⇒ Promise.<(Array.<document>\|\*)>
* _inner_
* [~execFnWithCallback](#Cursor..execFnWithCallback) : function
* [~execFnWithoutCallback](#Cursor..execFnWithoutCallback) ⇒ Promise
\| \*
* [~execCallback](#Cursor..execCallback) : function
### new Cursor(db, query, [execFn], [hasCallback])
Create a new cursor for this collection
**Params** - db [Datastore
](#Datastore) - The datastore this cursor is bound to
- query [query
](#query) - The query this cursor will operate on
- [execFn] [execFnWithoutCallback
](#Cursor..execFnWithoutCallback) | [execFnWithCallback
](#Cursor..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](#Cursor..execFnWithoutCallback) rather than [execFnWithCallback](#Cursor..execFnWithCallback).
Datastore
](#Datastore)
**Kind**: instance property of [Cursor
](#Cursor)
**Access**: protected
### cursor.query : [query
](#query)
**Kind**: instance property of [Cursor
](#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
](#Cursor)
**Access**: protected
### cursor.limit(limit) ⇒ [Cursor
](#Cursor)
Set a limit to the number of results
**Kind**: instance method of [Cursor
](#Cursor)
**Params**
- limit Number
### cursor.skip(skip) ⇒ [Cursor
](#Cursor)
Skip a number of results
**Kind**: instance method of [Cursor
](#Cursor)
**Params**
- skip Number
### cursor.sort(sortQuery) ⇒ [Cursor
](#Cursor)
Sort results of the query
**Kind**: instance method of [Cursor
](#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
](#Cursor)
Add the use of a projection
**Kind**: instance method of [Cursor
](#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>
](#document)
Apply the projection.
This is an internal function. You should use [execAsync](#Cursor+execAsync) or [exec](#Cursor+exec).
**Kind**: instance method of [Cursor
](#Cursor)
**Access**: protected
**Params**
- candidates [Array.<document>
](#document)
### cursor.\_execAsync() ⇒ [Array.<document>
](#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)
### 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
](#Cursor)
**Access**: protected
**See**: Cursor#exec
**Params**
- _callback [execCallback
](#Cursor..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
](#Cursor)
**Params**
- _callback [execCallback
](#Cursor..execCallback)
### cursor.execAsync() ⇒ Promise.<(Array.<document>\|\*)>
Async version of [exec](#Cursor+exec).
**Kind**: instance method of [Cursor
](#Cursor)
**See**: Cursor#exec
### Cursor~execFnWithCallback : function
Has a callback
**Kind**: inner typedef of [Cursor
](#Cursor)
**Params**
- err Error
- res [?Array.<document>
](#document) | [document
](#document)
### Cursor~execFnWithoutCallback ⇒ Promise
\| \*
Does not have a callback, may return a Promise.
**Kind**: inner typedef of [Cursor
](#Cursor)
**Params**
- res [?Array.<document>
](#document) | [document
](#document)
### Cursor~execCallback : function
**Kind**: inner typedef of [Cursor
](#Cursor)
**Params**
- err Error
- res [Array.<document>
](#document) | \*
- If an execFn was given to the Cursor, then the type of this parameter is the one returned by the execFn.