Recommended way/place to create index on MongoDB collection for a web application

前端 未结 3 999
悲哀的现实
悲哀的现实 2021-01-05 16:07

I\'m using MongoDB for our web application. Assume there will be a \'find()\' on MongoDB for incoming requests. What is the recommended way/place to add index on a MongoDB c

3条回答
  •  离开以前
    2021-01-05 17:05

    I would put it when you initialize the application. If the collection does not exist when you call ensureIndex, the index (and collection) will be created at that time.

    I am assuming that you know a priori what kinds of queries you will be running on the data, and what kind of data you will be putting into the index, of course.

提交回复
热议问题