0

We're running a huge MongoDB with a large index (made of of four fields) which was created ad-hoc and should now be superseded by slimmer one (of the first two fields). But the problem is we can't just delete the old one as the warmup of the new one may take hours (or days!). We have two secondary instances, is it possible to only delete the large index on one of those and have that instance take over when the new index is warmed? Or is there some way to guide Mongo to the new indices?

Edit: on a small test database Mongo rejects the new index after I delete the old one and instead uses half of third index, even though the new one is a perfect fit for the query. How to guide/update the query plan?

0

I tried this on a collection with millions of documents, and hope this is going to work in a multi-billon document collection:

  1. Create the index in the background. This can seriously hurt your .finds. We got timeouts for the duration of the index creation.
  2. Clear the plan cache.
  3. Create a script to scan all your data with hint to warm the index.
  4. Delete the old index.
  5. Clear the plan cache again.
  6. Try to find some data with the new index, and ensure it's used with explain. You must use different keys each time to ensure explain does not cache your query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.