The JavaScript Database, for Node.js, nw.js, electron and the browser
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
nedb/docs/Cursor.md

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

new Cursor(db, query, [execFn], [hasCallback])

Create a new cursor for this collection

Params

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

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

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

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

Cursor~execFnWithoutCallback ⇒ Promise | *

Does not have a callback, may return a Promise.

Kind: inner typedef of Cursor
Params

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.