new Collection()
collection.js, line 10
Note: Do not instantiate directly.
Members
-
namestring
-
The name of the collection.
Methods
-
aggregate(pipeline){Cursor}
collection.js, line 88 -
Evaluate an aggregation framework pipeline.
Name Type Description pipeline
Array.<object> The pipeline. Returns:
Type Description Cursor Example
col.aggregate([ { $match: { x: { $lt: 8 } } }, { $group: { _id: '$x', array: { $push: '$y' } } }, { $unwind: '$array' } ]);
-
find(expr, projection_spec){Cursor}
collection.js, line 37 -
Open a cursor that satisfies the specified query criteria.
Name Type Description expr
object optional The query document to filter by. projection_spec
object optional Specification for projection. Returns:
Type Description Cursor Example
col.find({ x: 4, g: { $lt: 10 } }, { k: 0 });
-
findOne(expr, projection_spec, cb){Promise}
collection.js, line 57 -
Retrieve one document that satisfies the specified query criteria.
Name Type Description expr
object optional The query document to filter by. projection_spec
object optional Specification for projection. cb
function optional The result callback. Returns:
Type Description Promise Example
col.findOne({ x: 4, g: { $lt: 10 } }, { k: 0 });
-
insert(docs, cb){Promise}
collection.js, line 123 -
Name Type Description docs
object | Array.<object> Documents to insert. cb
function optional The result callback. Returns:
Type Description Promise Examples
col.insert([{ x: 4 }, { k: 8 }], (error) => { if (error) { throw error; } });
col.insert({ x: 4 }, (error) => { if (error) { throw error; } });
-
remove(expr, cb){Promise}
collection.js, line 215 -
Delete documents that match a filter.
Name Type Description expr
object The query document to filter by. cb
function optional The result callback. Returns:
Type Description Promise Example
col.remove({ x: { $ne: 10 } }, (error) => { if (error) { throw error; } });
-
update(expr, spec, cb){Promise}
collection.js, line 198 -
Update documents that match a filter.
Name Type Description expr
object The query document to filter by. spec
object Specification for updating. cb
function optional The result callback. Returns:
Type Description Promise Example
col.update({ age: { $gte: 18 } }, { adult: true }, (error) => { if (error) { throw error; } });