如何在 MongoDB shell 中中止正在运行的查询?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26940616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I abort a running query in the MongoDB shell?
提问by collisionTwo
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? Control+C
appears to crash the shell, and spits out a ton of errors. The silly solutions suggested in this postof course do not do anything. I understand that I could like open up another terminal tab and
run db.currentOp()
, find the operation ID, and then run db.killOp()
, but I can't believe that's the only solution. I must be missing something obvious.
我不敢相信我不得不问这个问题,但是如何停止我刚刚运行的查询,该查询现在正在运行,并且显然需要很长时间才能在 Mongo shell 中完成?Control+C
似乎使外壳崩溃,并吐出大量错误。这篇文章中建议的愚蠢解决方案当然没有任何作用。我知道我可以打开另一个终端选项卡并运行db.currentOp()
,找到操作 ID,然后运行db.killOp()
,但我不敢相信这是唯一的解决方案。我一定遗漏了一些明显的东西。
回答by Roozbeh Zabihollahi
回答by Alex Erygin
According to Mongo documentation, you should:
根据 Mongo文档,您应该:
- Obtain the current operation ID via
db.currentOp()
- Kill opp via
db.killOp()
- 通过获取当前操作ID
db.currentOp()
- 杀死 opp 通过
db.killOp()
Good example script can be found here.
好的示例脚本可以在这里找到。
回答by Yuriy Bosov
For sharded cluster:
对于分片集群:
db.currentOp()
db.killOp("shard_id:opid")
db.currentOp()
db.killOp("shard_id:opid")
For example:
例如:
db.killOp("shard0000:3134616")