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

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

db.killOp(opid)

操作 ID で指定された操作を終了します。操作とそれに対応する ID を見つけるには、$currentOp または db.currentOp() を参照してください。

The db.killOp() method has the following parameter:

Parameter
タイプ
説明

op

数値

操作 ID。

警告

Terminate running operations with extreme caution. Only use db.killOp() to terminate operations initiated by clients and do not terminate internal database operations.

このメソッドは、次の環境でホストされている配置で使用できます。

  • MongoDB Atlas はクラウドでの MongoDB 配置のための完全管理サービスです

重要

MongoDB Atlas は、このメソッドの使用を、操作を実行した MongoDB ユーザーに制限しています。すべてのコマンドに対する Atlas のサポートについては、「サポートされていないコマンド」を参照してください。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

The db.killOp() method can be run on a mongos and can kill queries (read operations) that are running on more than one shard in a cluster.

たとえば、シャーディングされたクラスターでクエリ操作を強制終了するには、次のようにします。

  1. クライアントがクエリを発行したのと同じ mongosで、次の localOps: trueで集計パイプライン $currentOpを実行し、強制終了するクエリ操作の opid を見つけます。

    use admin
    db.aggregate( [
    { $currentOp : { allUsers: true, localOps: true } },
    { $match : <filter condition> } // Optional. Specify the condition to find the op.
    // e.g. { op: "getmore", "command.collection": "someCollection" }
    ] )

    重要

    この集計操作は、クライアントがクエリを発行したのと同じ mongosで発行する必要があります。

  2. Once you find the query operation to kill, issue db.killOp() with the opid on the mongos:

    db.killOp(<opid of the query to kill>)

Tip

$currentOp内のlocalOpsパラメータ。

または、操作を実行中のシャード ノードから読み取り操作を見つけて強制終了することもできます。MongoDB は、強制終了操作を他のシャードと mongos インスタンスに伝達します。

  1. 操作が実行中のシャードの 1 つで、強制終了するクエリ操作の opid を見つけます。

    use admin
    db.aggregate( [
    { $currentOp : { allUsers: true } },
    { $match : <filter condition> } // Optional. Specify the condition to find the op.
    // e.g. { op: "getmore", "command.collection": "someCollection" }
    ] )
  2. Once you find the query operation to kill, issue db.killOp() with the opid on the shard member:

    db.killOp(<opid of the query to kill>)

    MongoDB は、強制終了操作を他のシャードと mongos インスタンスに伝達します。

セッション内

MongoDB ドライバーは、確認されていない書き込みを除くすべての操作をサーバー セッションに関連付けます。

書き込み操作がセッションに関連付けられている場合、mongoskillSessions コマンドを使用して、シャード全体の書き込み操作を強制終了できます。

  1. mongos で集計パイプライン $currentOp を実行して、lsid(論理セッション ID)を見つけます。

    use admin
    db.aggregate( [
    { $currentOp : { allUsers: true, localOps: true } },
    { $match : <filter condition> } // Optional. Specify the condition to find the op.
    // e.g. { "op" : "update", "ns": "mydb.someCollection" }
    ] )
    1. 返された lsid 情報を使用して、mongoskillSessions コマンドを発行し、シャードに対する操作を強制終了します。

      db.adminCommand( { killSessions: [
      { "id" : UUID("80e48c5a-f7fb-4541-8ac0-9e3a1ed224a4"), "uid" : BinData(0,"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=") }
      ] } )
セッションなし

書き込み操作がセッションに関連付けられていない場合は、書き込みに関連するすべてのシャードで操作を見つけて強制終了する必要があります。

  1. mongos から、集計パイプライン $currentOp を実行して、シャード上のクエリ操作の opid を見つけます。

    use admin
    db.aggregate( [
    { $currentOp : { allUsers: true } },
    { $match : <filter condition> } // Optional. Specify the condition to find the op.
    ] )

    mongos で実行すると、$currentOp は opids を "<shardName>:<opid on that shard>" の形式で返します。例:

    {
    "shard" : "shardB",
    ..
    "opid" : "shardB:79214",
    ...
    },
    {
    "shard" : "shardA",
    ..
    "opid" : "shardA:100913",
    ...
    },
  2. Using the opid information, issue db.killOp() on the mongos to kill the operation on the shards.

    db.killOp("shardB:79014");
    db.killOp("shardA:100813");

authorization で実行されているシステムでは、ユーザー自身のものでない操作を強制終了するには、ユーザーに killop 特権アクションを含むアクセス権が必要です。

mongod インスタンスでは、ユーザーは killop 特権アクションがなくても自分の操作を強制終了できます。