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

前端 未结 3 1028
悲哀的现实
悲哀的现实 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 16:49

    You could create a initialisation script for the collection to be run from the command line of your server (the Mongo docs discuss how to write Mongo scripts and run them from the CLI). Then have it run whenever mongod starts? The script could just call ensureIndex() on the collection object.

提交回复
热议问题