How to create multiple index in mongodb


Create a positive index of the name field and a reverse index of the age on the test collection


db.getCollection('test').createIndex({name:1, age:-1})


createIndex : Creates indexes on collections.


    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 1,
    "numIndexesAfter" : 2,
    "ok" : 1.0
Was this helpful?

I hope to help every developer quickly find the commands they need. Of course, you can also add your own commonly used commands for easy searching.