6.3 KiB
Cursor ⇐ Promise
Manage access to data, be it to find, update or remove it.
It extends Promise so that its methods are chainable & awaitable.
Kind: global class
Extends: Promise
- Cursor ⇐
Promise
- new Cursor(db, query, [execFn], [async])
- instance
- .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>|*)>
- .limit(limit) ⇒
- inner
- ~execFn :
function
- ~execFnAsync ⇒
Promise
- ~execCallback :
function
- ~execFn :
new Cursor(db, query, [execFn], [async])
Create a new cursor for this collection
Param | Type | Default | Description |
---|---|---|---|
db | Datastore |
The datastore this cursor is bound to |
|
query | query |
The query this cursor will operate on |
|
[execFn] | execFn | execFnAsync |
Handler to be executed after cursor has found the results and before the callback passed to find/findOne/update/remove |
|
[async] | boolean |
false |
If true, specifies that the |
cursor.limit(limit) ⇒ Cursor
Set a limit to the number of results
Kind: instance method of Cursor
Param | Type |
---|---|
limit | Number |
cursor.skip(skip) ⇒ Cursor
Skip a number of results
Kind: instance method of Cursor
Param | Type |
---|---|
skip | Number |
cursor.sort(sortQuery) ⇒ Cursor
Sort results of the query
Kind: instance method of Cursor
Param | Type | Description |
---|---|---|
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
Param | Type | Description |
---|---|---|
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
Kind: instance method of Cursor
Param | Type |
---|---|
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 which uses the executor
Kind: instance method of Cursor
Param | Type |
---|---|
_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
Param | Type |
---|---|
_callback | execCallback |
cursor.execAsync() ⇒ Promise.<(Array.<document>|*)>
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~execFn : function
Kind: inner typedef of Cursor
Param | Type |
---|---|
err | Error |
res | ?Array.<document> | document |
Cursor~execFnAsync ⇒ Promise
Kind: inner typedef of Cursor
Param | Type |
---|---|
res | ?Array.<document> | document |
Cursor~execCallback : function
Kind: inner typedef of Cursor
Param | Type | Description |
---|---|---|
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. |