Members
-
documents
-
Description
Get all documents of the collection.
Returns
Details
-
name
-
Description
Get the name of the collection.
Returns
Details
-
schema
-
Description
Get the registered schema of the collection.
Returns
Details
-
hasSchema
-
Description
Get whether the collection has a schema registered.
Returns
Details
-
created
-
Description
Get the date and time of creation for this collection.
Returns
Details
-
firstDocument
-
Description
Get the first document of the collection.
Returns
Details
-
lastDocument
-
Description
Get the last document of the collection.
Returns
Details
-
size
-
Description
Get the amount of documents of the collection.
Returns
Details
Methods
-
insert( ...docs ) → {Array.<string>}
-
Description
Insert new documents into the collection.
Parameters
Name Type Attributes Description docs
object <repeatable> Documents to insert. Passing an array of documents is also supported.
Returns
Fires
Details
-
insertOne( doc [, emitEvent ] ) → {string}
-
Description
Insert a single document into the collection.
Parameters
Name Type Attributes Default Description doc
object Document to insert.
emitEvent
boolean <optional> true Whether to emit the insert event.
Returns
Fires
Details
-
find( filter, resultInstance ) → {Array.<object>|Result}
-
Description
Find all documents in the collection that match the query or pass the filter function.
Parameters
Name Type Default Description filter
object | function Query object or filter function which will be applied on each document.
resultInstance
boolean false Whether to return a Result instance with the matching documents.
Returns
Examples
// Find all documents where the value of the property price is greater than or equal to 50. collection.find({ price: { greaterThanOrEqual: 50 } });
// Same result but using a function. collection.find((doc) => doc.price >= 50);
Fires
Details
-
where( filter, resultInstance ) → {Array.<object>|Result}
-
Description
Find all documents in the collection that match the query or pass the filter function.
Parameters
Name Type Default Description filter
object | function Query object or filter function which will be applied on each document.
resultInstance
boolean false Whether to return a Result instance with the matching documents.
Returns
Examples
// Find all documents where the value of the property price is greater than or equal to 50. collection.find({ price: { greaterThanOrEqual: 50 } });
// Same result but using a function. collection.find((doc) => doc.price >= 50);
Fires
Details
-
where( filter, resultInstance ) → {Array.<object>|Result}
-
Description
Find all documents in the collection that match the query or pass the filter function.
Parameters
Name Type Default Description filter
object | function Query object or filter function which will be applied on each document.
resultInstance
boolean false Whether to return a Result instance with the matching documents.
Returns
Examples
// Find all documents where the value of the property price is greater than or equal to 50. collection.find({ price: { greaterThanOrEqual: 50 } });
// Same result but using a function. collection.find((doc) => doc.price >= 50);
Fires
Details
-
findOne( filter ) → {object}
-
Description
Find the first document in the collection that matches the query or passes the filter function.
Parameters
Name Type Description filter
object | function Query object or filter function which will be applied on each document.
Returns
Examples
// Find the first document where the value of the roperty price is greater than or equal to 50. collection.findOne({ price: { greaterThanOrEqual: 50 } });
// Same result but using a function. collection.findOne((doc) => doc.price >= 50);
Fires
Details
-
findById( id ) → {object}
-
Description
Find the document with the matching ID.
Parameters
Name Type Description id
string ID of the document to retrieve.
Returns
Examples
collection.findById('1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed');
Details
-
removeExact( doc [, first ] ) → {object|Array.<object>}
-
Description
Remove all documents matching the given document from the collection.
Parameters
Name Type Attributes Default Description doc
object Document(-s) to remove.
first
boolean <optional> false Whether to remove only the first matching document.
Returns
Examples
// Remove the first matching document. collection.removeExact({ price: 50 }, true);
// Remove all matching documents. collection.removeExact({ price: 50 });
Fires
Details
-
remove( filter ) → {Array.<object>}
-
Description
Remove all documents in the collection that match the query or passes the filter function.
Parameters
Name Type Description filter
object | function Query object or filter function which will be applied on each document.
Returns
Examples
// Remove all documents where the value of the // property price is greater than or equal to 50. collection.remove({ price: { greaterThanOrEqual: 50 } });
// Same result but using a function. collection.remove((doc) => doc.price >= 50);
Fires
Details
-
removeOne( filter ) → {Array.<object>}
-
Description
Remove the first document in the collection that matches the query or passes the filter function.
Parameters
Name Type Description filter
object | function Query object or filter function which will be applied on each document.
Returns
Examples
// Remove the first document where the value of the // property price is greater than or equal to 50. collection.removeOne({ price: { greaterThanOrEqual: 50 } }); // or collection.removeOne((doc) => doc.price >= 50);
Fires
Details
-
removeById( id ) → {object}
-
Description
Remove the document with the matching ID.
Parameters
Name Type Description id
string ID of the document to remove.
Returns
Examples
collection.removeById('1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed');
Fires
Details
-
update( filter, updater ) → {Array.<object>}
-
Description
Update all documents in the collection that match the query or pass the custom filter function.
Parameters
Name Type Description filter
object | function Query object or filter function which will be applied on each document.
updater
object | function Object or update function which will be applied on each filtered document.
Returns
Examples
// Update all documents where the value of the property price is greater than or equal to 50 and set it to 49.99. collection.update( (doc) => doc.price >= 50, { price: 49.99 } );
Fires
Details
-
updateById( id, updater ) → {object}
-
Description
Update the document with the matching ID.
Parameters
Name Type Description id
string ID of the document to update.
updater
object | function Object or update function which will be applied on each filtered document.
Returns
Examples
collection.updateById( '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed', { price: 49.99 } );
Fires
Details
-
registerSchema( schema ) → {Schema}
-
Description
Register a schema to validate documents inserted into the collection.
Parameters
Name Type Description schema
Schema | object Schema to validate documents with.
Returns
Details
-
unregisterSchema() → {Schema}
-
Description
Unregister the schema which ultimately stops the collection from validating any further documents.
Returns
Details
-
cleanWithSchema( [ schema ] ) → {Array.<object>}
-
Description
Clean the collection from invalid documents using the passed in or registered schema.
Parameters
Name Type Attributes Description schema
Schema <optional> Schema instance to clean collection with.
Returns
Details
-
clear() → {Array.<object>}
-
Description
Clear the collection by deleting all of its documents.
Returns
Details