Once created they act just like regular indexes. They persist in getIndexes
just as a reminder, similar to how unique
, sparse
and so on do.
But it also has the other meaning. Just because foreground indexes block all writers, in this case you won't be able to perform db.testCollection.getIndexes()
until all indexes have been created. Meanwhile when you create background index, then you can call db.testCollection.getIndexes()
and you will see, that index seems to be already created.
But in this case we can't be sure whether indexes have been actually created or not. In this case you need to call db.currentOp() and if you see something like
{
"inprog": [
{
"opid": 2001060,
"active": true,
"secs_running": 1,
"op": "insert",
"ns": "test.system.indexes",
"insert": {
"v": 1,
"key": {
"a": 1
},
"ns": "test.testCollection",
"name": "a_1",
"background": 1
},
....
"msg": "bg index build Background Index Build Progress: 368640/1000000 36%",
"progress": {
"done": 368640,
"total": 1000000
}
...
}
]
}
then it means, that creation of background indexes is still in progress, and also you can see some information about the process.
For example you may do some rough calculations: 368640 out of 1000000 takes 1 seconds (+1 second as possible offset), therefore everything should take 3-6 seconds (eventually it took 4.8 s).
Obviously if you can't see such operation in progress, then indexes are already created.
Note: if you have many concurrent operations, then you may specify searсh argument for db.currentOp()
, f.e.
db.currentOp({"insert.background":1})