Anton Manevskiy
Anton Manevskiy

Reputation: 868

When Mongoengine rebuild indexes?

When Mongoengine rebuild(update) a information about indexes? I mean, if a added or change some field (added uniques or sparse option to filed) or added some meta info in model declaration. So question is:

Upvotes: 3

Views: 470

Answers (1)

Anton Manevskiy
Anton Manevskiy

Reputation: 868

Mongoengine do not rebuild index automaticly. Mongoengine track changes in models (btw dont work if you add sparse to your filed(if field dont have unique options)) and then fire the ensureIndex in mongoDB. But when its fire - make sure you delete oldest index version manualy(Mongoengine doesn't) in mongoDB.

The problem is:

  • if you add sparse to filed w.o unique option - this changes dont mapped in mongoDB index. You need to combine unique = True, sparse = True
  • If you change indexs in models - you need to manualy delete old indexes in mongoDB.

Upvotes: 1

Related Questions