重要
mongosh メソッド
This page documents a mongosh method. This is not the documentation for a language-specific driver, such as Node.js.
MongoDB API ドライバーについては、各言語の「MongoDB ドライバーのドキュメント」を参照してください。
定義
db.adminCommand(command)adminデータベースに対して指定された データベースコマンド を実行するためのヘルパーを提供します。Parameterタイプ説明commandドキュメントまたは文字列
ドキュメント 形式または文字列として指定される データベースコマンド 。文字列として指定する場合、コマンドには引数を含めることはできません。
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas はクラウドでの MongoDB 配置のための完全管理サービスです
注意
このコマンドは、すべての MongoDB Atlas クラスターでサポートされています。すべてのコマンドに対する Atlas のサポートについては、「サポートされていないコマンド」を参照してください。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
動作
db.adminCommand() runs commands against the admin database regardless of the database context in which it runs. The following commands are equivalent:
db.getSiblingDB("admin").runCommand(<command>) db.adminCommand(<command>)
使用可能な管理データベースコマンドの一覧については、「データベースコマンド」を参照してください。
注意
authorization で実行中の mongod、または mongos の場合、承認されたユーザーはデータベースコマンドを実行するための適切な特権を持っている必要があります。セキュリティ要件の詳細については、コマンドの参考ドキュメントを参照してください。
応答
このメソッドは、次のフィールドを含む応答ドキュメントを返します。
フィールド | 説明 |
|---|---|
<command result> | 実行された |
| コマンドが成功したか( |
| 操作の論理的な時間。MongoDB は論理時間を使用して操作を順序付けます。レプリカセットとシャーディングされたクラスターのみ。 コマンドが oplog エントリを生成しない場合(読み取り操作など)、その操作では論理クロックは進みません。この場合、
因果的に一貫性のあるセッションに関連付けられた操作の場合、MongoDB ドライバーは論理時間を使用して、読み取り操作と |
| 署名されたクラスター時間を返すドキュメント。クラスター時間は、操作の順序付けに使用される論理時間です。レプリカセットとシャーディングされたクラスターのみ。内部使用のみ。 このドキュメントには、以下のフィールドが含まれています。
|
例
killOp
The following example uses the db.adminCommand() method to execute a killOp command to terminate an operation with opid 724. killOp is an administrative command and must be run against the admin database.
db.adminCommand( { "killOp": 1, "op": 724 } )
renameCollection
The following example uses db.adminCommand() to execute the renameCollection administrative database command to rename the orders collection in the test database to orders-2016.
db.adminCommand( { renameCollection: "test.orders", to: "test.orders-2016" } )
createUser
The following example uses the db.adminCommand() method to create a user named bruce with the dbOwner role on the admin database.
Tip
passwordPrompt() メソッドを様々なユーザー認証管理メソッドやコマンドと組み合わせて使用すると、メソッドやコマンドの呼び出しでパスワードを直接指定する代わりに、パスワードの入力を求めるプロンプトが表示されます。ただし、以前のバージョンの mongo シェルと同様に、パスワードを直接指定することもできます。
db.adminCommand( { createUser: "bruce", pwd: passwordPrompt(), // or <cleartext password> roles: [ { role: "dbOwner", db: "admin" } ] } )