Mongodb: when to call ensureIndex?

后端 未结 7 943
囚心锁ツ
囚心锁ツ 2021-02-01 01:34

When should I call ensureIndex? Before inserting a single record, after inserting a single record, or before calling find()?

Regards,

Johnny

7条回答
  •  说谎
    说谎 (楼主)
    2021-02-01 02:10

    It doesn't matter, but you only have to do this once. If you want to batch insert a large amount of data to an empty collection then it is best to create the index after the inserts but otherwise it doesn't really matter.

提交回复
热议问题