For this OR query:
db.messages.find({ $or: [ { to: { $ne: null }, from: "xyz" }, { to: "xyz" } ] }).sort({_id: -1}).limit(50)
with following indices:
{to:1, from: 1, _id:-1} and {from:1, to:1, _id:-1}
mongo is always doing a full scan.
I was hoping that mongo could use these two indices and merge the results.
Do I need to split this into two queries (one for each OR clause) and merge myself? Or is there some other index that can help?
This is a known issue, https://jira.mongodb.org/browse/SERVER-1205, which you can vote for if it is very important for your use case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With