Reputation: 140
Say I added a document
db.search.save({terms:["10115","Berlin","Germany"]})
I added an index via:
db.search.ensureIndex({terms:1})
when searching over documents and making sure that only the index is fetched
db.search.find({terms:"Berlin"}, {terms:1,_id:0}).explain()
# note: causes the whole output of the array, which might cause some trouble?
# however, leaving it out doesn't change anything
I'd expect within .explain()
"indexOnly" : true
The cursor indicates that mongo is using the index (BtreeCursor terms_1). So I am wondering if mongo is able to output array indexes by only touching the index.
In the end I'd like to do a query such as:
db.search.find({terms:{$all:[/10115/i,/ger/i]}})
PS: I see that for the latter Regex could cause some trouble...at least thats my guess.
Thanks for your feedback.
Cheers
Upvotes: 2
Views: 341
Reputation: 4276
It is not currently possible to use covering index on arrays. This is because each element in the array is indexed separately so there is no entry in the index that include the entire array.
Upvotes: 2