AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

db.adminCommand()(mongoshメソッド)

重要

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: The fully managed service for MongoDB deployments in the cloud

注意

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

  • 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>

実行された command に固有の結果フィールド。

ok

コマンドが成功したか(1)失敗したか(0)を示す数値。

operationTime

操作の論理的な時間。MongoDB は論理時間を使用して操作を順序付けます。レプリカセットとシャーディングされたクラスターのみ。

コマンドが oplog エントリを生成しない場合(読み取り操作など)、その操作では論理クロックは進みません。この場合、 operationTime は、次を返します。

  • 読み取り対象 "local"、"snapshot"、および "linearizable" の場合、oplog 内の最新エントリのタイムスタンプ。

  • 読み取り保証 (read concern) "majority" の場合、読み取りの実行に使用されるスナップショットのタイムスタンプ。

因果的に一貫性のあるセッションに関連付けられた操作の場合、MongoDB ドライバーは論理時間を使用して、読み取り操作と afterClusterTime 期間を自動的に設定します。

$clusterTime

署名されたクラスター時間を返すドキュメント。クラスター時間は、操作の順序付けに使用される論理時間です。レプリカセットとシャーディングされたクラスターのみ。内部使用のみ。

このドキュメントには、以下のフィールドが含まれています。

  • clusterTime: ノードの最も高い既知のクラスター時間のタイムスタンプ。

  • signature: クラスター時間のハッシュとクラスター時間の署名に使用されたキーの ID を含むドキュメント。

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 } )

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"
}
)

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" }
]
}
)
このページを評価