From MongoDB Documentation
If you have a compound index on multiple fields, you can use it to query on the beginning subset of fields. So if you have an index on a,b,c you can use it query on [a] [a,b] [a,b,c]
So lets say i have document with this fields
- UserID
- Name
- Country
- ExtraField
My Index order is [UserID,Name,Country]
So if i have query like
var q = (from c in collection.AsQueryable()
where c.UserID == UserID
where Name = "test"
where Country = 1
where ExtraField = "check"
select c);
Does this query use index for first 3 parameters and then search for ExtraField without index?
If yes, then is it same on this query too
var q = (from c in collection.AsQueryable()
where c.UserID == UserID
where ExtraField = "check"
select c);