Last Updated: February 25, 2016
·
4.295K
· squiter85

Force mongo to use a specific index

MongoDB automatically choose what index it uses in determinated queries, but you can specify what index you want mongoDB uses.
To specify the index, you can use the hint() method after your query:

db.users.find().hint({name:1})

You can force mongo to do not use any index too:

db.users.find().hint({$natural:1})