Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb status of index creation job

I'm using MongoDB and have a collection with roughly 75 million records. I have added a compound index on two "fields" by using the following command:

db.my_collection.ensureIndex({"data.items.text":1, "created_at":1},{background:true}). 

Two days later I'm trying to see the status of the index creation. Running db.currentOp() returns {}, however when I try to create another index I get this error message:

cannot add index with a background operation in progress. 

Is there a way to check the status/progress of the index creation job?

One thing to add - I am using mongodb version 2.0.6. Thanks!

like image 554
Yair Avgar Avatar asked Mar 10 '14 19:03

Yair Avgar


People also ask

How do I know if my MongoDB index is working?

In MongoDB, you can use the cursor. explain() method or the db. collection. explain() method to determine whether or not a query uses an index.

Does MongoDB create index automatically?

MongoDB automatically determines whether to create a multikey index if the indexed field contains an array value; you do not need to explicitly specify the multikey type.

How do I see indexes in MongoDB?

Finding indexes You can find all the available indexes in a MongoDB collection by using the getIndexes method. This will return all the indexes in a specific collection. Result: The output contains the default _id index and the user-created index student name index.

What does create index do in MongoDB?

CreateIndex() Method. In MongoDB, indexes are special data structures that store some information related to the documents such that it becomes easy for MongoDB to find the right data file. The indexes are ordered by the value of the field specified in the index.


1 Answers

At the mongo shell, type below command to see the current progress:

rs0:PRIMARY> db.currentOp(true).inprog.forEach(function(op){ if(op.msg!==undefined) print(op.msg) })  Index Build (background) Index Build (background): 1431577/55212209 2% 
like image 73
Bajal Avatar answered Sep 18 '22 14:09

Bajal