0

Let's say I have a collection of blog posts. Each blog post has a field called tags, which is an array of strings.

When I retrieve these posts, I pass an array of tags called requirements. I want to make sure each post I get back has each tag from requirements.

Concretely, if I have 2 posts, 1 with tags #fun #stuff and the other with #stuff #doing, and I pass the array ['fun, 'stuff'] then I should only get the first post back.

$in does exactly what I'm trying to do, but isn't inclusive (it matches any value; I need to match all values).

I suppose I could dynamically construct queries using $and, but that seems clunky.

Is there a better way of doing this?

m52go
  • 343
  • 1
  • 3
  • 14
  • I think [this duplicate question](http://stackoverflow.com/questions/5366687/how-to-check-if-an-array-field-contains-a-unique-value-or-another-array-in-mongo) is more appropriate. – go-oleg Aug 13 '14 at 00:12
  • Thanks, actually, that's exactly what I need. Sorry. I searched, promise! :) – m52go Aug 13 '14 at 00:18

0 Answers0