How do I abort a running query in the MongoDB shell?

后端 未结 3 598
挽巷
挽巷 2021-02-05 00:49

I can\'t believe I have to ask this, but how do I stop a query I just ran, which is now running, and will obviously take a very long time to complete in the Mongo shell? C

相关标签:
3条回答
  • 2021-02-05 00:51

    According to Mongo documentation, you should:

    1. Obtain the current operation ID via db.currentOp()
    2. Kill opp via db.killOp()

    Good example script can be found here.

    0 讨论(0)
  • 2021-02-05 01:00

    Based on Alex's answer.

    1. Query current running operations:

      db.currentOp()
      

    1. Kill the operation based on opid

      db.killOp(30318806)
      
    0 讨论(0)
  • 2021-02-05 01:06

    For sharded cluster:

    1. db.currentOp()
    2. db.killOp("shard_id:opid")

    For example:

    db.killOp("shard0000:3134616")
    
    0 讨论(0)
提交回复
热议问题