|
| 1 | +<a name="Cursor"></a> |
| 2 | + |
| 3 | +## Cursor ⇐ <code>Promise</code> |
| 4 | +<p>Manage access to data, be it to find, update or remove it.</p> |
| 5 | +<p>It extends Promise so that its methods are chainable & awaitable.</p> |
| 6 | + |
| 7 | +**Kind**: global class |
| 8 | +**Extends**: <code>Promise</code> |
| 9 | + |
| 10 | +* [Cursor](#Cursor) ⇐ <code>Promise</code> |
| 11 | + * [new Cursor(db, query, [execFn], [async])](#new_Cursor_new) |
| 12 | + * _instance_ |
| 13 | + * [.limit(limit)](#Cursor+limit) ⇒ [<code>Cursor</code>](#Cursor) |
| 14 | + * [.skip(skip)](#Cursor+skip) ⇒ [<code>Cursor</code>](#Cursor) |
| 15 | + * [.sort(sortQuery)](#Cursor+sort) ⇒ [<code>Cursor</code>](#Cursor) |
| 16 | + * [.projection(projection)](#Cursor+projection) ⇒ [<code>Cursor</code>](#Cursor) |
| 17 | + * [.project(candidates)](#Cursor+project) ⇒ [<code>Array.<document></code>](#document) |
| 18 | + * [._execAsync()](#Cursor+_execAsync) ⇒ [<code>Array.<document></code>](#document) \| <code>Promise.<\*></code> |
| 19 | + * [._exec(_callback)](#Cursor+_exec) |
| 20 | + * [.exec(_callback)](#Cursor+exec) |
| 21 | + * [.execAsync()](#Cursor+execAsync) ⇒ <code>Promise.<(Array.<document>\|\*)></code> |
| 22 | + * _inner_ |
| 23 | + * [~execFn](#Cursor..execFn) : <code>function</code> |
| 24 | + * [~execFnAsync](#Cursor..execFnAsync) ⇒ <code>Promise</code> |
| 25 | + * [~execCallback](#Cursor..execCallback) : <code>function</code> |
| 26 | + |
| 27 | +<a name="new_Cursor_new"></a> |
| 28 | + |
| 29 | +### new Cursor(db, query, [execFn], [async]) |
| 30 | +<p>Create a new cursor for this collection</p> |
| 31 | + |
| 32 | + |
| 33 | +| Param | Type | Default | Description | |
| 34 | +| --- | --- | --- | --- | |
| 35 | +| db | [<code>Datastore</code>](#Datastore) | | <p>The datastore this cursor is bound to</p> | |
| 36 | +| query | [<code>query</code>](#query) | | <p>The query this cursor will operate on</p> | |
| 37 | +| [execFn] | [<code>execFn</code>](#Cursor..execFn) \| [<code>execFnAsync</code>](#Cursor..execFnAsync) | | <p>Handler to be executed after cursor has found the results and before the callback passed to find/findOne/update/remove</p> | |
| 38 | +| [async] | <code>boolean</code> | <code>false</code> | <p>If true, specifies that the <code>execFn</code> is of type [execFnAsync](#Cursor..execFnAsync) rather than [execFn](#Cursor..execFn).</p> | |
| 39 | + |
| 40 | +<a name="Cursor+limit"></a> |
| 41 | + |
| 42 | +### cursor.limit(limit) ⇒ [<code>Cursor</code>](#Cursor) |
| 43 | +<p>Set a limit to the number of results</p> |
| 44 | + |
| 45 | +**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
| 46 | + |
| 47 | +| Param | Type | |
| 48 | +| --- | --- | |
| 49 | +| limit | <code>Number</code> | |
| 50 | + |
| 51 | +<a name="Cursor+skip"></a> |
| 52 | + |
| 53 | +### cursor.skip(skip) ⇒ [<code>Cursor</code>](#Cursor) |
| 54 | +<p>Skip a number of results</p> |
| 55 | + |
| 56 | +**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
| 57 | + |
| 58 | +| Param | Type | |
| 59 | +| --- | --- | |
| 60 | +| skip | <code>Number</code> | |
| 61 | + |
| 62 | +<a name="Cursor+sort"></a> |
| 63 | + |
| 64 | +### cursor.sort(sortQuery) ⇒ [<code>Cursor</code>](#Cursor) |
| 65 | +<p>Sort results of the query</p> |
| 66 | + |
| 67 | +**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
| 68 | + |
| 69 | +| Param | Type | Description | |
| 70 | +| --- | --- | --- | |
| 71 | +| sortQuery | <code>Object.<string, number></code> | <p>sortQuery is { field: order }, field can use the dot-notation, order is 1 for ascending and -1 for descending</p> | |
| 72 | + |
| 73 | +<a name="Cursor+projection"></a> |
| 74 | + |
| 75 | +### cursor.projection(projection) ⇒ [<code>Cursor</code>](#Cursor) |
| 76 | +<p>Add the use of a projection</p> |
| 77 | + |
| 78 | +**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
| 79 | + |
| 80 | +| Param | Type | Description | |
| 81 | +| --- | --- | --- | |
| 82 | +| projection | <code>Object.<string, number></code> | <p>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.</p> | |
| 83 | + |
| 84 | +<a name="Cursor+project"></a> |
| 85 | + |
| 86 | +### cursor.project(candidates) ⇒ [<code>Array.<document></code>](#document) |
| 87 | +<p>Apply the projection</p> |
| 88 | + |
| 89 | +**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
| 90 | + |
| 91 | +| Param | Type | |
| 92 | +| --- | --- | |
| 93 | +| candidates | [<code>Array.<document></code>](#document) | |
| 94 | + |
| 95 | +<a name="Cursor+_execAsync"></a> |
| 96 | + |
| 97 | +### cursor.\_execAsync() ⇒ [<code>Array.<document></code>](#document) \| <code>Promise.<\*></code> |
| 98 | +<p>Get all matching elements |
| 99 | +Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne |
| 100 | +This is an internal function, use execAsync which uses the executor</p> |
| 101 | + |
| 102 | +**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
| 103 | +<a name="Cursor+_exec"></a> |
| 104 | + |
| 105 | +### cursor.\_exec(_callback) |
| 106 | +<p>Get all matching elements |
| 107 | +Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne |
| 108 | +This is an internal function, use exec which uses the executor</p> |
| 109 | + |
| 110 | +**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
| 111 | + |
| 112 | +| Param | Type | |
| 113 | +| --- | --- | |
| 114 | +| _callback | [<code>execCallback</code>](#Cursor..execCallback) | |
| 115 | + |
| 116 | +<a name="Cursor+exec"></a> |
| 117 | + |
| 118 | +### cursor.exec(_callback) |
| 119 | +<p>Get all matching elements |
| 120 | +Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne</p> |
| 121 | + |
| 122 | +**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
| 123 | + |
| 124 | +| Param | Type | |
| 125 | +| --- | --- | |
| 126 | +| _callback | [<code>execCallback</code>](#Cursor..execCallback) | |
| 127 | + |
| 128 | +<a name="Cursor+execAsync"></a> |
| 129 | + |
| 130 | +### cursor.execAsync() ⇒ <code>Promise.<(Array.<document>\|\*)></code> |
| 131 | +<p>Get all matching elements |
| 132 | +Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne</p> |
| 133 | + |
| 134 | +**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
| 135 | +<a name="Cursor..execFn"></a> |
| 136 | + |
| 137 | +### Cursor~execFn : <code>function</code> |
| 138 | +**Kind**: inner typedef of [<code>Cursor</code>](#Cursor) |
| 139 | + |
| 140 | +| Param | Type | |
| 141 | +| --- | --- | |
| 142 | +| err | <code>Error</code> | |
| 143 | +| res | [<code>?Array.<document></code>](#document) \| [<code>document</code>](#document) | |
| 144 | + |
| 145 | +<a name="Cursor..execFnAsync"></a> |
| 146 | + |
| 147 | +### Cursor~execFnAsync ⇒ <code>Promise</code> |
| 148 | +**Kind**: inner typedef of [<code>Cursor</code>](#Cursor) |
| 149 | + |
| 150 | +| Param | Type | |
| 151 | +| --- | --- | |
| 152 | +| res | [<code>?Array.<document></code>](#document) \| [<code>document</code>](#document) | |
| 153 | + |
| 154 | +<a name="Cursor..execCallback"></a> |
| 155 | + |
| 156 | +### Cursor~execCallback : <code>function</code> |
| 157 | +**Kind**: inner typedef of [<code>Cursor</code>](#Cursor) |
| 158 | + |
| 159 | +| Param | Type | Description | |
| 160 | +| --- | --- | --- | |
| 161 | +| err | <code>Error</code> | | |
| 162 | +| res | [<code>Array.<document></code>](#document) \| <code>\*</code> | <p>If an execFn was given to the Cursor, then the type of this parameter is the one returned by the execFn.</p> | |
| 163 | + |
0 commit comments