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?