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

前端 未结 3 1021
悲哀的现实
悲哀的现实 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:12

    Clearly run the ensureIndex when you start the application. It doesn't matter if you call the ensureIndex on an empty collection (as it will add the data afterwards to the index).

    Furthermore it depends on which property your queries are based. If you for example query based on the logged in user, then you should add the index on the user id.

提交回复
热议问题