0

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).

  1. 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.
  2. Any reason why the performance should degrade so much as the script progresses?
marmor
  • 27,641
  • 11
  • 107
  • 150
  • 1
    It should be much faster to add the field first and then add the index. Otherwise the index must be updated each time the field is added to another document. – JohnnyHK Nov 09 '16 at 14:47
  • @JohnnyHK thanks, we've dropped the index, and made sure mongo stopped building it, after restarting the script it, again, started off fast, but performance is getting worse by the minute, seems like this hasn't changed much. any idea why is the script slowing down? each document is updated once, i would expected it to run at a constant rate – marmor Nov 09 '16 at 15:38

0 Answers0