How to create multiple index in mongodb


 description

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

 command

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

 parameter

createIndex : Creates indexes on collections.

 result

{
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 1,
    "numIndexesAfter" : 2,
    "ok" : 1.0
}

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.