All command documentation outlined below describes a command and
its available parameters and provides a document template or prototype
for each command. Some command documentation also includes the relevant
mongosh helpers.
To run a command against the current database, use db.runCommand():
db.runCommand( { <command> } )
To run an administrative command against the admin database, use db.adminCommand():
db.adminCommand( { <command> } )
Note
For details on specific commands, including syntax and examples, click on the specific command to go to its reference page.
Command Syntax
When you run a database command, you specify the command as a document
to db.runCommand(). The document's key is the command to run,
and the value is typically supplied as 1. The value does not affect
the output of the command for example:
db.runCommand( { hello: 1 } )
User Commands
Aggregation Commands
Name | Description | MongoDB Atlas Support |
|---|---|---|
Performs aggregation tasks such as | Limited support for Free and Flex clusters. | |
Counts the number of documents in a collection or a view. | Limited support for Free and Flex clusters. | |
Displays the distinct values found for a specified key in a collection or a view. | Limited support for Free and Flex clusters. | |
Performs map-reduce aggregation for large data sets. | No support for Free and Flex clusters. |
Query and Write Operation Commands
Name | Description | MongoDB Atlas Support |
|---|---|---|
Deletes one or more documents. | Yes | |
Selects documents in a collection or a view. | Limited support for Free and Flex clusters. | |
Returns and modifies a single document. | Yes | |
Inserts one or more documents. | Yes | |
Updates one or more documents. | Yes |
Query Plan Cache Commands
Name | Description | MongoDB Atlas Support |
|---|---|---|
Removes cached query plan(s) for a collection. | No support for Free and Flex clusters. | |
Clears index filter(s) for a collection. | No support for Free and Flex clusters. | |
Lists the index filters for a collection. | No support for Free and Flex clusters. | |
Sets an index filter for a collection. | No support for Free and Flex clusters. |
Database Operations
Authentication Commands
Name | Description | MongoDB Atlas Support |
|---|---|---|
Starts an authenticated session using a username and password. | No support for Free and Flex clusters. | |
Terminates the current authenticated session. | Yes |
User Management Commands
Name | Description | MongoDB Atlas Support |
|---|---|---|
Creates a new user. | No support for Flex clusters, Free, and M10 clusters. | |
Deletes all users associated with a database. | No support for Free and Flex clusters. | |
Removes a single user. | No support for M10 clusters. | |
Grants a role and its privileges to a user. | No support for Flex clusters, Free, and M10 clusters. | |
Removes a role from a user. | No support for Flex clusters, Free, and M10 clusters. | |
Updates a user's data. | No support for Flex clusters, Free, and M10 clusters. | |
Returns information about the specified users. | Limited support for Free and Flex clusters. |
Role Management Commands
Name | Description | MongoDB Atlas Support |
|---|---|---|
Creates a role and specifies its privileges. | No support for Flex clusters, Free, and M10 clusters. | |
Deletes the user-defined role. | No support for Flex clusters, Free, and M10 clusters. | |
Deletes all user-defined roles from a database. | No support for Free and Flex clusters. | |
Assigns privileges to a user-defined role. | No support for Free and Flex clusters. | |
Specifies roles from which a user-defined role inherits privileges. | No support for Free and Flex clusters. | |
Flushes the in-memory cache of user information, including credentials and roles. | No support for Free and Flex clusters. | |
Removes the specified privileges from a user-defined role. | No support for Free and Flex clusters. | |
Removes specified inherited roles from a user-defined role. | No support for Free and Flex clusters. | |
Returns information for the specified role or roles. | Yes | |
Updates a user-defined role. | No support for Flex clusters, Free, and M10 clusters. |
Replication Commands
Name | Description | MongoDB Atlas Support |
|---|---|---|
Writes a non-operational entry to the oplog. | No support for Free and Flex clusters. | |
Internal command that applies oplog entries to the current data set. | Yes | |
Displays information about this member's role in the replica set, including whether it is the primary. | Yes | |
Forces the elected primary to abort sync (catch up) then complete the transition to primary. | Yes | |
Prevents the current member from seeking election as primary for a period of time. | No support for Flex clusters, Free, and M10 clusters. | |
Returns the replica set's configuration object. | No support for Free and Flex clusters. | |
Returns a document that reports on the status of the replica set. | No support for Free and Flex clusters. | |
Initializes a new replica set. | No support for Flex clusters, Free, and M10 clusters. | |
Enables or disables a maintenance mode, which puts a secondary node in a | No support for Flex clusters, Free, and M10 clusters. | |
Applies a new configuration to an existing replica set. | No support for Flex clusters, Free, and M10 clusters. | |
Dynamically resizes the oplog for a replica set member. Available for WiredTiger storage engine only. | No support for M10 clusters. | |
No support for Flex clusters, Free, and M10 clusters. | ||
Explicitly override the default logic for selecting a member to replicate from. | No support for Flex clusters, Free, and M10 clusters. |
Tip
Replication for more information regarding replication.
Sharding Commands
Name | Description | MongoDB Atlas Support |
|---|---|---|
Adds a shard to a sharded cluster. | Yes | |
Yes | ||
Calculates metrics for evaluating a shard key. New in version 7.0. | Yes | |
Returns information on whether the chunks of a sharded collection are balanced. | Yes | |
Starts a balancer thread. | Yes | |
Returns information on the balancer status. | Yes | |
Stops the balancer thread. | Yes | |
Performs a series of consistency checks on sharding metadata. New in version 7.0. | Yes | |
Clears the | Yes | |
Removes orphaned data with shard key values outside of the ranges of the chunks owned by a shard. | No support for M0, M2, and M5 clusters. | |
Cleans up a failed resharding operation. | Yes | |
Forces a resharding operation to block writes and complete. | Yes | |
Configures balancer settings on a sharded collection. | Yes | |
Configures query sampling for a collection. New in version 7.0. | Yes | |
Creates a database. | Yes | |
Yes | ||
Internal command that reports on the state of a sharded cluster. | No support for Free and Flex clusters. | |
Verifies that a process is a | Yes | |
Returns a list of configured shards. | Yes | |
Internal command that migrates chunks between shards. | Yes | |
Reassigns the primary shard when removing a shard from a sharded cluster. | Yes | |
Moves ranges between shards. | Yes | |
Merges all mergeable chunks that a shard owns for a given collection. | Yes | |
Provides the ability to combine chunks on a single shard. | Yes | |
Refines a collection's shard key by adding a suffix to the existing key. | No support for M10 clusters. | |
Starts the process of removing a shard from a sharded cluster. | No support for M10 clusters. | |
Yes | ||
Initiates a resharding operation to change the shard key for a collection, changing the distribution of your data. | Yes | |
Prevents new automatic migrations on a collection. | Yes | |
Enables the sharding functionality for a collection, allowing the collection to be sharded. | Yes | |
Reports whether the | Yes | |
Creates a new chunk. | Yes | |
Removed in MongoDB 5.0. Internal command that affects connections between instances in a MongoDB deployment. | Yes | |
Yes |
Tip
Sharding for more information about MongoDB's sharding functionality.
Session Commands
Command | Description | Atlas Support |
|---|---|---|
Abort transaction. | Yes | |
Commit transaction. | Yes | |
Expire sessions before the sessions' timeout period. | Yes | |
Kill all sessions. | No support for Flex clusters, Free, and M10 clusters. | |
Kill all sessions that match the specified pattern | No support for Free and Flex clusters. | |
Kill specified sessions. | No support for Free and Flex clusters. | |
Refresh idle sessions. | Yes | |
Starts a new session. | Yes |
Administration Commands
Name | Description | MongoDB Atlas Support |
|---|---|---|
Copies a non-capped collection as a new capped collection. | No support for Free and Flex clusters. | |
Add options to a collection or modify a view definition. | Yes | |
Defragments a collection and rebuilds the indexes. | No support for Free and Flex clusters. | |
Compacts documents specified in the state collections and deletes redundant documents. | Yes | |
Converts a non-capped collection to a capped collection. | Yes | |
Creates a collection or a view. | Yes | |
Builds one or more indexes for a collection. | Yes | |
Returns a document that contains information on in-progress operations for the database instance. | Yes | |
Removes the specified collection from the database. | Yes | |
Removes the current database. | Yes | |
Drops outgoing connections to the specified list of hosts. | Yes | |
Removes indexes from a collection. | Yes | |
Yes | ||
Flushes pending writes to the storage layer and locks the database to allow backups. | No support for Flex clusters, Free, and M10 clusters. | |
Unlocks one fsync lock. | No support for Free and Flex clusters. | |
Retrieves the global default read and write concern options for the deployment. | Yes | |
Retrieves cluster parameter values from all nodes in a cluster. New in version 6.0. | Yes | |
Retrieves configuration options. | Limited support for Free and Flex clusters. | |
Kills the specified cursors for a collection. | Yes | |
Terminates an operation as specified by the operation ID. | Limited support for Free, M10, and Flex clusters. | |
Returns a list of collections in the current database. | Yes | |
Returns a document that lists all databases and returns basic database statistics. | Yes | |
Lists all indexes for a collection. | Yes | |
Rotates the MongoDB logs to prevent a single file from taking too much space. | No support for Flex clusters, Free, and M10 clusters. | |
Rebuilds all indexes on a collection. | No support for Free and Flex clusters. | |
Changes the name of an existing collection. | Yes | |
Performs online TLS certificate rotation. | Yes | |
Enables or disables features that persist data that are backwards-incompatible. | No support for Flex clusters, Free, and M10 clusters. | |
Changes the minimum number of data-bearing members (i.e commit quorum), including the primary, that must vote to commit an in-progress index build before the primary marks those indexes as ready. | Yes | |
Modifies configuration options for all nodes in a replica set or sharded cluster. New in version 6.0. | Yes | |
Modifies configuration options. | No support for Flex clusters, Free, and M10 clusters. | |
Blocks and unblocks writes to the entire cluster. | No | |
Sets the global default read and write concern options for the deployment. | Yes | |
No support for Flex clusters, Free, and M10 clusters. | ||
Checks that the stored metadata of a database or a collection is valid within a particular API version. | Yes |
Diagnostic Commands
Name | Description | MongoDB Atlas Support |
|---|---|---|
Displays statistics about the MongoDB build. | Yes | |
Reports storage utilization statics for a specified collection. | Yes | |
Reports statistics on the outgoing connections from this MongoDB instance to other MongoDB instances in the deployment. | Yes | |
Reports the authentication state for the current connection. | Yes | |
Returns the data size for a range of data. For internal use. | No support for Free and Flex clusters. | |
Returns hash value a database and its collections. | No support for Free and Flex clusters. | |
Reports storage utilization statistics for the specified database. | Limited support for Free and Flex clusters. | |
Returns information on the execution of various operations. | Yes | |
Returns a document with the run-time arguments to the MongoDB instance and their parsed options. | Yes | |
Returns recent log messages. | Yes | |
Returns data that reflects the underlying host system. | No support for Free and Flex clusters. | |
Lists all database commands provided by the current | Yes | |
Internal command that returns information on locks that are
currently being held or pending. Only available for
| No support for Free and Flex clusters. | |
Internal command that tests intra-deployment connectivity. | Yes | |
Interface for the database profiler. | Yes | |
Returns a collection metrics on instance-wide resource utilization and status. | Yes | |
Removed in MongoDB 5.0. Use | Yes | |
Returns raw usage statistics for each database in the | Yes | |
Internal command that scans for a collection's data and indexes for correctness. | No support for Free and Flex clusters. | |
Internal command that returns information on the current client. | Yes |
Auditing Commands
Name | Description | MongoDB Atlas Support |
|---|---|---|
No | ||
Posts a custom message to the audit log. | Yes | |
No |
Atlas Search Commands
New in version 7.0: (Also available starting in 6.0.7)
Name | Description |
|---|---|
Creates one or more Atlas Search indexes on a specified collection. | |
Deletes an existing Atlas Search index. | |
Updates an existing Atlas Search index. |