Movatterモバイル変換


[0]ホーム

URL:


MongoDB.local SF, Jan 15: See the speaker lineup & ship your AI vision faster. Use WEB50 to save 50%
Find out more >
Docs Menu

Database Commands

All command documentation outlined below describes a command andits available parameters and provides a document template or prototypefor each command. Some command documentation also includes the relevantmongosh helpers.

To run a command against the current database, usedb.runCommand():

db.runCommand( { <command> } )

To run an administrative command against theadmin database, usedb.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.

Command Syntax

When you run a database command, you specify the command as a documenttodb.runCommand(). The document's key is the command to run,and the value is typically supplied as1. The value does not affectthe output of the command for example:

db.runCommand( {hello:1 } )

User Commands

Aggregation Commands

Name
Description
MongoDB Atlas Support

Performsaggregation tasks such as$group using an aggregation pipeline.

Limited support forFree and Flex clusters.

Counts the number of documents in a collection or a view.

Limited support forFree and Flex clusters.

Displays the distinct values found for a specified key in a collection or a view.

Limited support forFree and Flex clusters.

Performsmap-reduce aggregation for large data sets.

Query and Write Operation Commands

Name
Description
MongoDB Atlas Support

Performs many insert, update, and delete operations on multiplecollections in one request.

New in version 8.0.

Yes

Deletes one or more documents.

Yes

Selects documents in a collection or a view.

Limited support forFree 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.

Clears index filter(s) for a collection.

Lists the index filters for a collection.

Sets an index filter for a collection.

Database Operations

Authentication Commands

Name
Description
MongoDB Atlas Support

Starts an authenticated session using a username and password.

Terminates the current authenticated session.

Yes

User Management Commands

Name
Description
MongoDB Atlas Support

Creates a new user.

Deletes all users associated with a database.

Removes a single user.

No support forM10 clusters.

Grants a role and its privileges to a user.

Removes a role from a user.

Updates a user's data.

Returns information about the specified users.

Limited support forFree and Flex clusters.

Role Management Commands

Name
Description
MongoDB Atlas Support

Creates a role and specifies its privileges.

Deletes the user-defined role.

Deletes all user-defined roles from a database.

Assigns privileges to a user-defined role.

Specifies roles from which a user-defined role inherits privileges.

Flushes the in-memory cache of user information, including credentials and roles.

Removes the specified privileges from a user-defined role.

Removes specified inherited roles from a user-defined role.

Returns information for the specified role or roles.

Yes

Updates a user-defined role.

Replication Commands

Name
Description
MongoDB Atlas Support

Writes a non-operational entry to theoplog.

Internal command that appliesoplog 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 electedprimary to abort sync (catch up) then complete the transition to primary.

Yes

Prevents the current member from seeking election asprimary for a period of time.

Returns the replica set's configuration object.

Returns a document that reports on the status of the replica set.

Initializes a new replica set.

Enables or disables a maintenance mode, which puts asecondary node in aRECOVERING state.

Applies a new configuration to an existing replica set.

Dynamically resizes the oplog for a replica set member. Available for WiredTiger storage engine only.

No support forM10 clusters.

Forces the currentprimary tostep down and become asecondary, forcing an election.

Explicitly override the default logic for selecting a member to replicate from.

Tip

Replication for more information regardingreplication.

Sharding Commands

Name
Description
MongoDB Atlas Support

Yes

Stops an in-progressmoveCollection operation.

New in version 8.0.

No support for AtlasFree and Flex tier.

Stops an in-progressunshardCollection operation.

New in version 8.0.

No support for AtlasFree and Flex tier.

Yes

Associates a shard with azone. Supports configuringzones in sharded clusters.

Yes

Calculates metrics for evaluating a shard key.

New in version 7.0.

Yes

Returns information on whether the chunks of a shardedcollection 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 thejumbo flag for a chunk.

Yes

Cleans up a failedresharding operation.

Yes

Forces aresharding operation toblock 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

Forces amongod /mongos instance to update its cached routing metadata.

Yes

Internal command that reports on the state of a sharded cluster.

Verifies that a process is amongos.

Yes

Returns a list of configured shards.

Yes

Internal command that migrates chunks between shards.

Yes

Moves a single unsharded collection to a different shard.

Yes

Reassigns theprimary shard when removing a shard from a sharded cluster.

Yes

Moves ranges between shards.

Yes

Merges allmergeable chunks that a shardowns 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 theexisting key.

No support forM10 clusters.

Starts the process of removing a shard from a sharded cluster.

No support forM10 clusters.

Removes the association between a shard and azone. Supports configuringzones in sharded clusters.

Yes

Initiates aresharding operation to change theshard key for a collection, changing the distribution of your data.

Yes

Prevents newautomatic migrations on a collection.

Yes

Enables the sharding functionality for a collection, allowing the collection to be sharded.

Yes

Reports whether themongod is a member of a sharded cluster.

Yes

Creates a newchunk.

Yes

Configures a dedicated config server to run as a config shard.

New in version 8.0.

No support for AtlasFree and Flex tier.

Configures a config shard to run as a dedicated config server.

New in version 8.0.

No support for AtlasFree and Flex tier.

Removed in MongoDB 5.0. Internal command that affectsconnections between instances in a MongoDB deployment.

Yes

Unshards an existing sharded collection and moves the collectiondata onto a single shard. When you unshard a collection,the collection cannot be partitioned across multipleshards and theshard key is removed.

New in version 8.0.

Yes

Adds or removes the association between a range of sharded data and azone. Supports configuringzones in sharded clusters.

Yes

Tip

Sharding for more information about MongoDB'ssharding functionality.

Session Commands

Command
Description
Atlas Support

Abort transaction.

Yes

Commit transaction.

Yes

Expire sessions before the sessions' timeout period.

Yes

Kill all sessions.

Kill all sessions that match the specified pattern

Kill specified sessions.

Refresh idle sessions.

Yes

Starts a new session.

Yes

Administration Commands

Name
Description
MongoDB Atlas Support

Copies a non-capped collection as a newcapped collection.

Add options to a collection or modify a view definition.

Yes

Defragments a collection and rebuilds the indexes.

Compacts documents specified in the state collections anddeletes 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

Deprecated. Returns themd5 hash for files stored usingGridFS.

Yes

Flushes pending writes to the storage layer and locks the database to allow backups.

Unlocks one fsync lock.

Retrieves the global default read and write concern optionsfor the deployment.

Yes

Retrieves cluster parameter values from all nodes in a cluster.

New in version 6.0.

Yes

Retrieves configuration options.

Limited support forFree and Flex clusters.

Kills the specified cursors for a collection.

Yes

Terminates an operation as specified by the operation ID.

Limited support forFree,M10, andFlex 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.

Rebuilds all indexes on a collection.

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.

Changes the minimum number of data-bearing members (i.e commitquorum), including the primary, that must vote to commit anin-progressindex build before the primary marksthose indexes as ready.

Yes

Modifies configuration options for all nodes in a replica set orsharded cluster.

New in version 6.0.

Yes

Modifies configuration options.

Sets the global default read and write concern options for thedeployment.

Yes

Blocks and unblocks writes to the entire cluster.

No

Shuts down themongod ormongos process.

Checks that the stored metadata of a database or a collectionis 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.

Returns hash value a database and its collections.

Reports storage utilization statistics for the specified database.

Limited support forFree 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.

Lists all database commands provided by the currentmongod instance.

Yes

Internal command that returns information on locks that arecurrently being held or pending. Only available formongod instances.

Internal command that tests intra-deployment connectivity.

Yes

Interface for thedatabase profiler.

Yes

Returns a collection metrics on instance-wide resource utilization and status.

Yes

Removed in MongoDB 5.0. UseconnPoolStats instead.

Yes

Returns raw usage statistics for each database in themongod instance.

Yes

Internal command that scans for a collection's data and indexes for correctness.

Internal command that returns information on the current client.

Yes

Auditing Commands

Name
Description
MongoDB Atlas Support

Deprecated in version 7.1: Use theauditConfig clusterparameter instead.

Retrieves audit configurations frommongod andmongos instances.

No

Posts a custom message to the audit log.

Yes

Deprecated in version 7.1: Use theauditConfig clusterparameter instead.

Sets audit configurations formongod andmongos instances at runtime.

No

MongoDB Search Commands

New in version 7.0: (Also available starting in 6.0.7)

Name
Description

Creates one or moreMongoDB Search indexes on a specified collection or view.

Deletes an existingMongoDB Search index.

Updates an existingMongoDB Search index.


[8]ページ先頭

©2009-2025 Movatter.jp