I have a field _keywords
which is an array of strings. I want to get documents of which _keywords
are super-set of the query array.
For example
Short answer: $all operator.
To query documents with array with superset of ['foo1', 'foo2'], use:
db.article.find( { '_keywords': { $all: ['foo1', 'foo2'] } } );
In MongoDb, for array field:
"$in:[...]" means "intersection" or "any element in",
"$all:[...]" means "subset" or "contain",
"$elemMatch:{...}" means "any element match"
"$not:{$elemMatch:{$nin:[...]}}" means "superset" or "in"
Use the $all
operator:
db.article.find( { _keywords: { $all: [ 'foo1', 'foo2' ] } } );
Source: http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24all