We need to add a new field along with an index to a huge collection of documents in mongodb
.
We've created an index for the new field, and then started running a script that uses UnorderedBulkOp
to update each document and add that field to it.
The script started relatively fast (111 sec/million), but is getting slower and slower as it progresses (currently down to 422 sec/million).
- was it the right decision to first add the index and then add the field? we're aware that this will slow down the updates as it now needs to update the index, but we assumed it will save time building the index from scratch when the script is done.
- Any reason why the performance should degrade so much as the script progresses?