Creating background indexes
In the previous recipes, whenever we've created indexes, it has always been in the foreground that is, the database server blocks all changes to the database until the index creation is completed. This is definitely not suitable for larger datasets where index creation time can take a few seconds which could be application errors.
Getting ready
Load the sample dataset, as shown in the Creating an index recipe.
How to do it...
- Remove all indexes:
> db.mockdata.dropIndexes() { "nIndexesWas" : 2, "msg" : "non-_id indexes dropped for collection", "ok" : 1 }
- Add some additional data to increase the size of our collection. Run the following command string in your Terminal window:
for x in $(seq 20); do mongoimport --headerline --type=csv -d mydb -c mockdata -h localhost chapter_2_mock_data.csv;done
- Open two mongo shells, we will create an index in one while we do an insert query in another. Ensure you've selected
mydb
by executing the commanduse mydb
...