Database Commands (original) (raw)
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 relevantmongosh 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 a specific command, including syntax and examples, click on the link to the command's reference page.
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 } )
| Name | Description | MongoDB Atlas Support |
|---|---|---|
| bulkWrite | Performs many insert, update, and delete operations on multiple collections in one request.New in version 8.0. | Yes |
| delete | Deletes one or more documents. | Yes |
| find | Selects documents in a collection or a view. | Limited support for Free and Flex clusters. |
| findAndModify | Returns and modifies a single document. | Yes |
| insert | Inserts one or more documents. | Yes |
| update | Updates one or more documents. | Yes |
| Name | Description | MongoDB Atlas Support |
|---|---|---|
| appendOplogNote | Writes a non-operational entry to the oplog. | No support for Free and Flex clusters. |
| applyOps | Internal command that applies oplog entries to the current data set. | Yes |
| hello | Displays information about this member's role in the replica set, including whether it is the primary. | Yes |
| replSetAbortPrimaryCatchUp | Forces the elected primary to abort sync (catch up) then complete the transition to primary. | Yes |
| replSetFreeze | Prevents the current member from seeking election as primary for a period of time. | No support for Flex clusters, Free,and M10 clusters. |
| replSetGetConfig | Returns the replica set's configuration object. | No support for Free and Flex clusters. |
| replSetGetStatus | Returns a document that reports on the status of the replica set. | No support for Free and Flex clusters. |
| replSetInitiate | Initializes a new replica set. | No support for Flex clusters, Free,and M10 clusters. |
| replSetMaintenance | Enables or disables a maintenance mode, which puts a secondary node in a RECOVERING state. | No support for Flex clusters, Free,and M10 clusters. |
| replSetReconfig | Applies a new configuration to an existing replica set. | No support for Flex clusters, Free,and M10 clusters. |
| replSetResizeOplog | Dynamically resizes the oplog for a replica set member. Available for WiredTiger storage engine only. | No support for M10 clusters. |
| replSetStepDown | Forces the current primary to step down and become a secondary, forcing an election. | No support for Flex clusters, Free,and M10 clusters. |
| replSetSyncFrom | 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.
Tip
Sharding for more information about MongoDB's sharding functionality.
| Name | Description | MongoDB Atlas Support |
|---|---|---|
| cloneCollectionAsCapped | Copies a non-capped collection as a new capped collection. | No support for Free and Flex clusters. |
| collMod | Add options to a collection or modify a view definition. | Yes |
| compact | Defragments a collection and rebuilds the indexes. | No support for Free and Flex clusters. |
| compactStructuredEncryptionData | Compacts documents specified in the state collections and deletes redundant documents. | Yes |
| convertToCapped | Converts a non-capped collection to a capped collection. | Yes |
| create | Creates a collection or a view. | Yes |
| createIndexes | Builds one or more indexes for a collection. | Yes |
| currentOp | Returns a document that contains information on in-progress operations for the database instance. | Yes |
| drop | Removes the specified collection from the database. | Yes |
| dropDatabase | Removes the current database. | Yes |
| dropConnections | Drops outgoing connections to the specified list of hosts. | Yes |
| dropIndexes | Removes indexes from a collection. | Yes |
| filemd5 | Deprecated. Returns the md5 hash for files stored using GridFS. | Yes |
| fsync | Flushes pending writes to the storage layer and locks the database to allow backups. | No support for Flex clusters, Free,and M10 clusters. |
| fsyncUnlock | Unlocks one fsync lock. | No support for Free and Flex clusters. |
| getDefaultRWConcern | Retrieves the global default read and write concern options for the deployment. | Yes |
| getClusterParameter | Retrieves cluster parameter values from all nodes in a cluster.New in version 6.0. | Yes |
| getParameter | Retrieves configuration options. | Limited support for Free and Flex clusters. |
| killCursors | Kills the specified cursors for a collection. | Yes |
| killOp | Terminates an operation as specified by the operation ID. | Limited support for Free, M10, andFlex clusters. |
| listCollections | Returns a list of collections in the current database. | Yes |
| listDatabases | Returns a document that lists all databases and returns basic database statistics. | Yes |
| listIndexes | Lists all indexes for a collection. | Yes |
| logRotate | Rotates the MongoDB logs to prevent a single file from taking too much space. | No support for Flex clusters, Free,and M10 clusters. |
| reIndex | Rebuilds all indexes on a collection. | No support for Free and Flex clusters. |
| renameCollection | Changes the name of an existing collection. | Yes |
| rotateCertificates | Performs online TLS certificate rotation. | Yes |
| setFeatureCompatibilityVersion | Enables or disables features that persist data that are backwards-incompatible. | No support for Flex clusters, Free,and M10 clusters. |
| setIndexCommitQuorum | 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 |
| setClusterParameter | Modifies configuration options for all nodes in a replica set or sharded cluster.New in version 6.0. | Yes |
| setParameter | Modifies configuration options. | No support for Flex clusters, Free,and M10 clusters. |
| setDefaultRWConcern | Sets the global default read and write concern options for the deployment. | Yes |
| setUserWriteBlockMode | Blocks and unblocks writes to the entire cluster. | No |
| shutdown | Shuts down the mongod or mongos process. | No support for Flex clusters, Free,and M10 clusters. |
| validateDBMetadata | Checks that the stored metadata of a database or a collection is valid within a particular API version. | Yes |
New in version 7.0: (Also available starting in 6.0.7)