mongo createIndex 后台阻塞shell [英] mongo createIndex background blocks the shell
问题描述
我正在为几千兆位的文档创建索引.
I am creating an index on a few Gigabits of documents.
在我的 mongo shell 中,我运行了这个命令:
In my mongo shell, I ran this command:
db.positions.createIndex( { "imei": 1, "server_date": -1 }, { "background": true, "name": "positions_imei_server_date" } );
然而,即使背景设置为 true,我也没有得到 shell 提示.
However I did not get the shell prompt back even with background set at true.
如果我查看日志,我会看到:
If I look in the log, I see:
[conn13] Index Build (background): 14129300/19197181 73%
所以看起来它真的是作为后台任务运行的.但是为什么我没有在 shell 中取回提示?正常吗?如果我输入 CTRL+C 会取消我的索引吗?
So it seems that it is really running as a background task. However why did I not get back the prompt in the shell? Is it normal? If I type CTRL+C will it cancel my index?
我正在运行 mongo 3.4.0
I am running the mongo 3.4.0
推荐答案
这是预期的行为.background 意味着在您正在构建索引的数据库中列出集合等操作不会阻塞.但是,您启动的 shell 命令仍在运行.您可以简单地打开另一个 shell 并连接到服务器.发出 CTRL+C 将中止索引创建.
This is the expected behavior. background means that operations like listing collection in the database you're building the index on won't block. However the shell command you started remains running. You can simply open another shell and connect to the server. Issuing CTRL+C will abort the index creation.
在此处查看更多信息:https://docs.mongodb.com/v3.0/core/index-creation/#background-construction
这篇关于mongo createIndex 后台阻塞shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!