2

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I had this in mind (see my note). I also did some testing and it seems that not fetching the terms field doesnt make any difference...unless there are any magic tricks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.