I understand that with MongoDB, for a query to make use of a compound index it must use ALL of the keys in the index, or at least some of the keys starting from the left. For example
db.products.find({ "a":"foo", "b":"bar" })
Will happily make use of an index made up of {a, b, c}.
However, if I want to query:
db.products.find( {"a":"foo", "c":"thing" })
I believe this can't use the index. Could this be solved by adding a trivial condition on "b", e.g.
db.products.find( {"a":"foo", "b":{ $ne : "" }, "c":"thing" })
Even when I don't actually care about the value of b. The reason for this is that we currently have 45m objects, and it's going to continue growing so we're looking to consolidate our indexes to save on resources.
Many thanks.