How we can create an Index on MongoDB?

前端 未结 2 1283
忘掉有多难
忘掉有多难 2020-12-31 13:31

I want to create Index on Mongo database for performance prespective, so could you please help me how I can do it?

Your help will be appreciated here.

2条回答
  •  旧时难觅i
    2020-12-31 14:09

    The basic syntax is:

    db.collection.createIndex(keys, options)

    So, for example:

    $ db.users.createIndex({"username" : 1})

    See MongoDB Indexes for the full details.

提交回复
热议问题