Reputation: 815
I like to know the internal process of how mongo query works. I had gone through the source code of Mongo. But, I could not find the right way to understand it.
Mongo Query 1:
db.collection.find({
class : 10,
subject:"Physics",
name :"John Doe"
});
Mongo Query 2:
db.collection.find({
name :"John Doe",
class : 10,
subject:"Physics",
});
Consider a scenario, in a collection, if the name value -"John Doe" occurs only twice and class value - 10 occurs hundred times, will the second query executes faster or will both queries take same response time. Is the order of query matters?
Upvotes: 2
Views: 1356
Reputation: 7080
Its all depends on index
, MongoDB will give preferences for Indexed key at first.
You can use Explain which gives results that you want such as how many records have been processed to get this result, is there any index key in your query.
I love using Compass Which gives explains query visually.
Upvotes: 1