Skip to content
MongoDB

Collection API Reference

MongoDB collection methods for inserting, querying, updating and aggregating documents.

By EZ4Code Team

Collection

Collection-level operations exposed by the driver and mongo shell.

collection.insertOne(document, options?) -> InsertOneResult

Inserts a single document into the collection.

Returns: InsertOneResult

collection.find(query, projection?) -> Cursor

Returns a cursor over documents matching the query, optionally projecting fields.

Returns: Cursor

collection.updateOne(filter, update, options?) -> UpdateResult

Updates the first document matching filter using update operators such as $set.

Returns: UpdateResult

collection.deleteOne(filter, options?) -> DeleteResult

Deletes the first document matching the filter.

Returns: DeleteResult

collection.aggregate(pipeline, options?) -> Cursor

Runs an aggregation pipeline returning a cursor over the resulting documents.

Returns: Cursor

collection.countDocuments(filter, options?) -> number

Returns the number of documents matching the filter.

Returns: number

More MongoDB API References