Collection Methods
This version of the documentation is archived and no longer
supported. View the current documentation to learn how to
upgrade your version of MongoDB.
Note
mongo Shell Methods
The methods listed on this table of contents page refer to the
mongo
shell methods, and not to the MongoDB Node.js
driver (or any other driver) methods. For corresponding MongoDB driver
API, refer to your specific MongoDB driver
documentation instead.
Note
For details on a specific method, including syntax and examples, click on the link to the method's reference page.
Name | Description |
---|---|
Provides access to the aggregation pipeline. | |
Provides bulk write operation functionality. | |
Deprecated. Copies data between collections when run against MongoDB 4.0 or earlier. Unsupported when run against MongoDB 4.2 or later. | |
Wraps count to return a count of the number of documents in a collection or a view. | |
Wraps count to return an approximate count of the documents in a collection or a view. | |
Builds an index on a collection. | |
Builds one or more indexes on a collection. | |
Returns the size of the collection. Wraps the size field in the output of the collStats . | |
Deletes a single document in a collection. | |
Deletes multiple documents in a collection. | |
Returns an array of documents that have distinct values for the specified field. | |
Removes the specified collection from the database. | |
Removes a specified index on a collection. | |
Removes all indexes on a collection. | |
Deprecated. Use db.collection.createIndex() . | |
Returns information on the query execution of various methods. | |
Performs a query on a collection or a view and returns a cursor object. | |
Atomically modifies and returns a single document. | |
Performs a query and returns a single document. | |
Finds a single document and deletes it. | |
Finds a single document and replaces it. | |
Finds a single document and updates it. | |
Returns an array of documents that describe the existing indexes on a collection. | |
For collections in sharded clusters, db.collection.getShardDistribution() reports data of chunk distribution. | |
Internal diagnostic method for sharded cluster. | |
Hides an index from the query planner. | |
Creates a new document in a collection. | |
Inserts a new document in a collection. | |
Inserts several new document in a collection. | |
Reports if a collection is a capped collection. | |
Returns latency statistics for a collection. | |
Performs map-reduce style data aggregation. | |
Rebuilds all existing indexes on a collection. | |
Deletes documents from a collection. | |
Changes the name of a collection. | |
Replaces a single document in a collection. | |
Reports on the state of a collection. Provides a wrapper around the collStats . | |
Reports the total size used by the collection in bytes. Provides a wrapper around the storageSize field of the collStats output. | |
Reports the total size used by the indexes on a collection. Provides a wrapper around the totalIndexSize field of the collStats output. | |
Reports the total size of a collection, including the size of all documents and all indexes on a collection. | |
Unhides an index from the query planner. | |
Modifies a document in a collection. | |
Modifies a single document in a collection. | |
Modifies multiple documents in a collection. | |
Establishes a Change Stream on a collection. | |
Performs diagnostic operations on a collection. |