Kind: global class
- Cursor
- .sort() ⇒
Cursor
- .skip() ⇒
Cursor
- .limit() ⇒
Cursor
- .project() ⇒
Cursor
- .exec() ⇒
Promise.<Array.<Object>>
- .then(fulfilled, [rejected]) ⇒
Promise
- .catch(rejected) ⇒
Promise
- .sort() ⇒
cursor.sort() ⇒ Cursor
Sort the queried documents.
See: https://github.com/louischatriot/nedb#sorting-and-paginating
Kind: instance method of Cursor
cursor.skip() ⇒ Cursor
Skip some of the queried documents.
See: https://github.com/louischatriot/nedb#sorting-and-paginating
Kind: instance method of Cursor
cursor.limit() ⇒ Cursor
Limit the queried documents.
See: https://github.com/louischatriot/nedb#sorting-and-paginating
Kind: instance method of Cursor
cursor.project() ⇒ Cursor
Set the document projection.
See: https://github.com/louischatriot/nedb#projections
Kind: instance method of Cursor
Execute the cursor.
Since the Cursor has a then
and a catch
method
JavaScript identifies it as a thenable object
thus you can await it in async functions.
Kind: instance method of Cursor
Example
// in an async function
await datastore.find(...)
.sort(...)
.limit(...)
Example
// the previous is the same as:
await datastore.find(...)
.sort(...)
.limit(...)
.exec()
Execute the cursor and set promise callbacks.
For more information visit: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
Kind: instance method of Cursor
Param | Type |
---|---|
fulfilled | function |
[rejected] | function |
Execute the cursor and set promise error callback.
For more information visit: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
Kind: instance method of Cursor
Param | Type |
---|---|
rejected | function |
Kind: global class
Summary: As of v2.0.0 the Datastore class extends node's built
in EventEmitter class and implements each method as an event
plus additional error events. It also inherits the compaction.done
event from nedb but for consistency, in this library the event
was renamed to compactionDone
.
All event callbacks will be passed the same type of values, the first being the datastore, then the operation result (if there is any) and then the arguments of the called method. (Check out the first example!)
All events have a matching error event that goes by the name of ${method}Error
,
for example findError
or loadError
. The callbacks of these events will receive
the same parameters as the normal event handlers except that instead of the
operation result there will be an operation error. (Check out the second example!)
A generic __error__
event is also available. This event will be emitted at any of
the above error events. The callbacks of this event will receive the same parameters
as the specific error event handlers except that there will be one more parameter
passed between the datastore and the error object, that being the name of the method
that failed. (Check out the third example!)
- Datastore
- new Datastore([pathOrOptions])
- instance
- .load() ⇒
Promise.<undefined>
- .find([query], [projection]) ⇒
Cursor
- .findOne([query], [projection]) ⇒
Cursor
- .insert(docs) ⇒
Promise.<(Object|Array.<Object>)>
- .insertOne(doc) ⇒
Promise.<Object>
- .insertMany(docs) ⇒
Promise.<Array.<Object>>
- .update(query, update, [options]) ⇒
Promise.<(number|Object|Array.<Object>)>
- .updateOne(query, update, [options]) ⇒
Promise.<(number|Object)>
- .updateMany(query, update, [options]) ⇒
Promise.<(number|Array.<Object>)>
- .remove([query], [options]) ⇒
Promise.<number>
- .removeOne([query], [options]) ⇒
Promise.<number>
- .removeMany([query], [options]) ⇒
Promise.<number>
- .deleteOne([query], [options]) ⇒
Promise.<number>
- .deleteMany([query], [options]) ⇒
Promise.<number>
- .count([query]) ⇒
Cursor
- .ensureIndex(options) ⇒
Promise.<undefined>
- .removeIndex(field) ⇒
Promise.<undefined>
- .load() ⇒
- static
- .create([pathOrOptions]) ⇒
Proxy.<static>
- .create([pathOrOptions]) ⇒
Datastore constructor...
You should use Datastore.create(...)
instead
of new Datastore(...)
. With that you can access
the original datastore's properties such as datastore.persistence
.
Create a Datastore instance.
Note that the datastore will be created
relative to process.cwd()
(unless an absolute path was passed).
It's basically the same as the original: https://github.com/louischatriot/nedb#creatingloading-a-database
Param | Type |
---|---|
[pathOrOptions] | string | Object |
Example
let datastore = Datastore.create()
datastore.on('update', (datastore, result, query, update, options) => {
})
datastore.on('load', (datastore) => {
// this event doesn't have a result
})
datastore.on('ensureIndex', (datastore, options) => {
// this event doesn't have a result
// but it has the options argument which will be passed to the
// event handlers
})
datastore.on('compactionDone', (datastore) => {
// inherited from nedb's compaction.done event
})
Example
let datastore = Datastore.create()
datastore.on('updateError', (datastore, error, query, update, options) => {
})
datastore.on('loadError', (datastore, error) => {
})
datastore.on('ensureIndexError', (datastore, error, options) => {
})
Example
let datastore = Datastore.create()
datastore.on('__error__', (datastore, event, error, ...args) => {
// for example
// datastore, 'find', error, [{ foo: 'bar' }, {}]
})
Load the datastore.
Note that you don't necessarily have to call
this method to load the datastore as it will
automatically be called and awaited on any
operation issued against the datastore
(i.e.: find
, findOne
, etc.).
Kind: instance method of Datastore
datastore.find([query], [projection]) ⇒ Cursor
Find documents that match the specified query
.
It's basically the same as the original: https://github.com/louischatriot/nedb#finding-documents
There are differences minor in how the cursor works though.
Kind: instance method of Datastore
Param | Type |
---|---|
[query] | Object |
[projection] | Object |
Example
datastore.find({ ... }).sort({ ... }).exec().then(...)
Example
datastore.find({ ... }).sort({ ... }).then(...)
Example
// in an async function
await datastore.find({ ... }).sort({ ... })
datastore.findOne([query], [projection]) ⇒ Cursor
Find a document that matches the specified query
.
It's basically the same as the original: https://github.com/louischatriot/nedb#finding-documents
Kind: instance method of Datastore
Param | Type |
---|---|
[query] | Object |
[projection] | Object |
Example
datastore.findOne({ ... }).then(...)
Example
// in an async function
await datastore.findOne({ ... }).sort({ ... })
Insert a document or documents.
It's basically the same as the original: https://github.com/louischatriot/nedb#inserting-documents
Kind: instance method of Datastore
Param | Type |
---|---|
docs | Object | Array.<Object> |
Insert a single document.
This is just an alias for insert
with object destructuring
to ensure a single document.
Kind: instance method of Datastore
Param | Type |
---|---|
doc | Object |
Insert multiple documents.
This is just an alias for insert
with array destructuring
to ensure multiple documents.
Kind: instance method of Datastore
Param | Type |
---|---|
docs | Array.<Object> |
Update documents that match the specified query
.
It's basically the same as the original: https://github.com/louischatriot/nedb#updating-documents
If you set options.returnUpdatedDocs
,
the returned promise will resolve with
an object (if options.multi
is false
) or
with an array of objects.
Kind: instance method of Datastore
Param | Type |
---|---|
query | Object |
update | Object |
[options] | Object |
Update a single document that matches the specified query
.
This is just an alias for update
with options.multi
set to false
.
Kind: instance method of Datastore
Param | Type |
---|---|
query | Object |
update | Object |
[options] | Object |
Update multiple documents that match the specified query
.
This is just an alias for update
with options.multi
set to true
.
Kind: instance method of Datastore
Param | Type |
---|---|
query | Object |
update | Object |
[options] | Object |
Remove documents that match the specified query
.
It's basically the same as the original: https://github.com/louischatriot/nedb#removing-documents
Kind: instance method of Datastore
Param | Type |
---|---|
[query] | Object |
[options] | Object |
Remove the first document that matches the specified query
.
This is just an alias for remove
with options.multi
set to false
.
Kind: instance method of Datastore
Param | Type |
---|---|
[query] | Object |
[options] | Object |
Remove all documents that match the specified query
.
This is just an alias for remove
with options.multi
set to true
.
Kind: instance method of Datastore
Param | Type |
---|---|
[query] | Object |
[options] | Object |
Remove the first document that matches the specified query
.
This is just an alias for removeOne
.
Kind: instance method of Datastore
Param | Type |
---|---|
[query] | Object |
[options] | Object |
Remove all documents that match the specified query
.
This is just an alias for removeMany
.
Kind: instance method of Datastore
Param | Type |
---|---|
[query] | Object |
[options] | Object |
datastore.count([query]) ⇒ Cursor
Count documents matching the specified query
.
It's basically the same as the original: https://github.com/louischatriot/nedb#counting-documents
Kind: instance method of Datastore
Param | Type |
---|---|
[query] | Object |
Example
datastore.count({ ... }).limit(...).then(...)
Example
// in an async function
await datastore.count({ ... })
// or
await datastore.count({ ... }).sort(...).limit(...)
https://github.com/louischatriot/nedb#indexing
Kind: instance method of Datastore
Param | Type |
---|---|
options | Object |
https://github.com/louischatriot/nedb#indexing
Kind: instance method of Datastore
Param | Type |
---|---|
field | string |
Create a database instance.
Use this over new Datastore(...)
to access
original nedb datastore properties, such as
datastore.persistence
.
Note that this method only creates the Datastore
class instance, not the datastore file itself.
The file will only be created once an operation
is issued against the datastore or if you call
the load
instance method explicitly.
The path (if specified) will be relative to process.cwd()
(unless an absolute path was passed).
For more information visit: https://github.com/louischatriot/nedb#creatingloading-a-database
Kind: static method of Datastore
Param | Type |
---|---|
[pathOrOptions] | string | Object |