Root
Root

Reputation: 147

How to disable mongodb index while update large collection

My requirement is to update or add an array field into large collection. I've index on filed "Roles". While update this collection it is taking arounf 3 miniutes .. Before creating index on "role" filed it was taking less than 40 sec to update/add fileds in the collection. We need the index to read the collection . But while update it makes trouble. Is it possible to disable index while update in mongodb.. Is there any funtions available with mongo? My mongodb version is 2.6.5

Please advice.

Upvotes: 2

Views: 6799

Answers (2)

Clement Amarnath
Clement Amarnath

Reputation: 5466

In Mongodb Indexes are updated synchronously with the insert/update. There is no way to pause the update of Indexes.

If your indexes are already created then you have two options

  1. Drop the index and recreate the index, but it will have the following impacts

    1. Queries executed at the time of the insert/update is happening will miss the index.
    2. Rebuilding index is too expensive
  2. Wait for the index to be updated

Upvotes: 5

Tarion
Tarion

Reputation: 17134

Queries will not use partially-built indexes: the index will only be usable once the index build is complete.

Source: http://docs.mongodb.org/manual/core/index-creation/

That means your index will block any query on the field/collection as long as the index is not complete. Therefore your have no chance but waiting for the index to be updated after adding new data.

Maybe try using another index.

Upvotes: 1

Related Questions