views:

247

answers:

1

My doc has an array field Keys

Keys1 and Keys2 are two arrays

I want all the docs where Keys contains any value in Keys1 AND any value in Keys2

Any advice?

Thanks

+2  A: 

There's no great way to represent this query yet (as of 1.1.2) - if you ask on the list or file a feature request we can try to get something cooked up.

For now the best bet is probably to use an $in query to do half of the work:

db.test.find({keys: {$in: Keys1}})

You can do this in combination with a $where which can do the Keys2 part (but won't take advantage of an index - that's why it is good to do as much as possible with the regular query syntax). This would look something like this:

db.test.find({keys: {$in: Keys1}, $where: "for (i in this.keys) { for (j in Keys2) { if (this.keys[i] == Keys2[j]) return true;}} return false;"})

mdirolf