开发者

MongoDB and covering index on arrays possible?

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 indic开发者_开发知识库ates 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜