-
Type: New Feature
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Querying
-
None
-
Query
-
Fully Compatible
Summary
$only would select the document where the queried field is an array that only contains the specified values. (If the queried field isn't an array, then the operator is identical to $in.)
Example
> db.foo.drop() > db.foo.insert( { a: [ "a", "b" ] } ) > db.foo.insert( { a: [ "a", "d" ] } ) > db.foo.insert( { a: [ "d", "e" ] } ) > db.foo.find( { a: { $in: [ "a", "b", "c" ] } } ) { a: [ "a", "b" ] } { a: [ "a", "d" ] } > db.foo.find( { a: { $only: [ "a", "b", "c" ] } } ) { a: [ "a", "b" ] }
More details
$nin already has semantics of checking all elements in the document array to make sure none of them are in the supplied array. This suggestion is just like that, except it should check that every element is in the target array (instead of is not in the target array as $nin does). i.e. compare the above to:
> db.foo.find( { a: { $nin: [ "a", "b", "c" ] } } ) { a: [ "d", "e" ] }
$all is not what I'm looking for:
> db.foo.find( { a: { $all: [ "a", "b", "c" ] } } ) >
- depends on
-
SERVER-9366 Expose projection (aggregation) operators in regular find queries
- Closed
- duplicates
-
SERVER-974 $subset query operator
- Closed