Search code examples
mongodbindexingdatabase-performance

best strategy to upgrade mongo 2dsphere index version with minimum performance impact


We have recently upgraded from mongo 3.0 to 3.2 The application uses 2dsphere index heavily which is still at version 2.0. We want to upgrade this 2dshpere index version to 3.0 to avail performance benefits that comes with it.

But the collection on which this needs to be done has more than 10 Million nodes and the application is a heavy traffic application that we can't afford to impact for long.

What should be our strategy to get this done with minimum impact on performance on real time traffic queries.

Suggested solution:

1) Create new 2dshpere index in background with version 3.0
2) After above is done, remove old 2dsphere index

Please suggest the best possible solution for the same or above is the best one can do for this use case.


Solution

  • I am posting my own answer as what we used worked well for us. Would love to hear a better answer if any.

    We first created version 3 index in background. So that both the indexes are there on parallel.

     db.goibibocms_nodes.createIndex({"fieldname":"2dsphere","background":1,"version":3},{"2dsphereIndexVersion":3})
    

    Then we dropped the version 2 index.

     db.goibibocms_nodes_v2.dropIndex("old index name")
    

    And it went off well without any performance downgrade when these index creation and drop was taking place.