- Reference >
- Operators >
- Aggregation Pipeline Operators >
- $setIsSubset (aggregation)
$setIsSubset (aggregation)¶
On this page
Definition¶
-
$setIsSubset
¶ Takes two arrays and returns
true
when the first array is a subset of the second, including when the first array equals the second array, andfalse
otherwise.$setIsSubset
has the following syntax:The arguments can be any valid expression as long as they each resolve to an array. For more information on expressions, see Expressions.
Behavior¶
$setIsSubset
performs set operation on arrays, treating arrays
as sets. If an array contains duplicate entries, $setIsSubset
ignores the duplicate entries. $setIsSubset
ignores the order of
the elements.
If a set contains a nested array element, $setIsSubset
does not descend
into the nested array but evaluates the array at top-level.
Example | Result |
---|---|
true |
|
false |
Example¶
Consider an experiments
collection with the following documents:
The following operation uses the $setIsSubset
operator to
determine if the A
array is a subset of the B
array:
The operation returns the following results: