db.mytable.ensureIndex({"odadd.n": 1,"odadd.cmp": 1,"adadd.Address.n": 1,"adadd.Address.cmp": 1})
db.mytable.find({"$or": [{"odadd.n": "AMY"},{"odadd.cmp": "AMY"},{"adadd.Address.n": "AMY"},{"adadd.Address.cmp": "AMY"}]
Queries with $or use multiple index plans in parallel, so you actually want a separate index on each of the fields of the $or query. This is the exception to normal queries, that need one compound index per query.
Yes.
To explain a little further how the indexes work why that's the case, an index on a, b is generally not useful for a query on b, since it is ordered by a first then secondarily b so it can't find things just on b. So when one of the clauses of the or is on b, it can't use that index.
I hope that helps,
-- Max
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb