Docs Menu
Docs Home
/
MongoDB Manual
/ /

Collection Methods

Note

mongosh Methods

The methods listed on this table of contents page are mongosh methods. This is not the documentation for Node.js or other programming language specific driver methods.

In most cases, mongosh methods work the same way as the legacy mongo shell methods. However, some legacy methods are unavailable in mongosh.

For MongoDB API drivers, refer to the language specific MongoDB driver documentation.

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.

Wraps count to return a count of the number of documents in a collection or a view.

Wraps the $group aggregation stage with a $sum expression to return a count of the number of 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.

Wraps count to return an approximate count of the documents in a collection or a view.

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.

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 single document in a collection.

Modifies multiple documents in a collection.

Establishes a Change Stream on a collection.

Performs diagnostic operations on a collection.

Back

mongosh Methods