- Reference >
- Operators >
- Aggregation Pipeline Operators >
- $setEquals (aggregation)
$setEquals (aggregation)¶
On this page
Definition¶
-
$setEquals
¶ Compares two or more arrays and returns
true
if they have the same distinct elements andfalse
otherwise.$setEquals
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¶
$setEquals
performs set operation on arrays, treating arrays
as sets. If an array contains duplicate entries, $setEquals
ignores the duplicate entries. $setEquals
ignores the order of
the elements.
If a set contains a nested array element, $setEquals
does not descend
into the nested array but evaluates the array at top-level.
Example | Result | |
---|---|---|
{ $setEquals: [ [ "a", "b", "a" ], [ "b", "a" ] ] } |
true |
|
{ $setEquals: [ [ "a", "b" ], [ [ "a", "b" ] ] ] } |
false |
Example¶
Consider an experiments
collection with the following documents:
The following operation uses the $setEquals
operator to
determine if the A
array and the B
array
contain the same elements:
The operation returns the following results: