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})
Written by Brunno dos Santos
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Mongodb
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#