Class: Collection

Collection() → {Collection}

Create a new Collection instance (not meant to be instantiated directly).

Constructor

new Collection() → {Collection}

Returns:

a Collection instance.

Type
Collection

Methods

aggregate(pipeline) → {Array}

Executes an aggregation pipeline.

Parameters:
Name Type Description
pipeline Array

The aggregation pipeline.

Returns:

The results of the aggregation.

Type
Array

count(query, options) → {Number}

Gets the number of documents matching the filter.

Parameters:
Name Type Description
query Object

The query used to match documents.

options Object

Additional count options.

Properties
Name Type Attributes Default Description
limit Number <optional>
null

The maximum number of documents to return.

Returns:

The results of the count operation.

Type
Number

deleteMany(query) → {Promise.<Object, Error>}

Deletes all documents matching query.

Parameters:
Name Type Description
query Object

The query used to match the documents to delete.

Returns:

Returns a Promise for the operation.

Type
Promise.<Object, Error>

deleteOne(query) → {Promise.<Object, Error>}

Deletes a single document.

Parameters:
Name Type Description
query Object

The query used to match a single document.

Returns:

Returns a Promise for the operation.

Type
Promise.<Object, Error>

find(query, projectopt) → {MongoQuery}

Finds documents.

Parameters:
Name Type Attributes Description
query Object

The query used to match documents.

project Object <optional>

The query document projection.

Returns:

An object which allows for limit and sort parameters to be set.
execute will return a {Promise} for the operation.

Type
MongoQuery

findOne(query, projectopt) → {Promise.<Object, Error>}

Finds one document.

Parameters:
Name Type Attributes Description
query Object

The query used to match documents.

project Object <optional>

The query document projection.

Returns:

Returns a Promise for the operation

Type
Promise.<Object, Error>

insertMany(docs) → {Promise.<Object, Error>}

Inserts multiple documents.

Parameters:
Name Type Description
docs Array

The documents to insert.

Returns:

Returns a Promise for the operation.

Type
Promise.<Object, Error>

insertOne(doc) → {Promise.<Object, Error>}

Inserts a single document.

Parameters:
Name Type Description
doc Object

The document to insert.

Returns:

a Promise for the operation.

Type
Promise.<Object, Error>

updateMany(query, update, optionsopt) → {Promise.<Object, Error>}

Updates multiple documents.

Parameters:
Name Type Attributes Description
query Object

The query used to match the documents.

update Object

The update operations to perform on the matching documents.

options Object <optional>

Additional options object.

Properties
Name Type Attributes Default Description
upsert Boolean <optional>
false

Perform an upsert operation.

Returns:

Returns a Promise for the operation.

Type
Promise.<Object, Error>

updateOne(query, update, optionsopt) → {Promise.<Object, Error>}

Updates a single document.

Parameters:
Name Type Attributes Description
query Object

The query used to match a single document.

update Object

The update operations to perform on the matching document.

options Object <optional>

Additional options object.

Properties
Name Type Attributes Default Description
upsert Boolean <optional>
false

Perform an upsert operation.

Returns:

A Promise for the operation.

Type
Promise.<Object, Error>