I am creating an index on a few Gigabits of documents.

In my mongo shell, I ran this command:

db.positions.createIndex( { "imei": 1, "server_date": -1 }, { "background": true, "name": "positions_imei_server_date" } );

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%

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?

I am running the mongo 3.4.0


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.

See more here: https://docs.mongodb.com/v3.0/core/index-creation/#background-construction

Your Answer

