- Reference >
- Operators >
- Aggregation Pipeline Operators >
- Set Operators (Aggregation) >
- $setEquals (aggregation)
$setEquals (aggregation)¶
On this page
Definition¶
-
$setEquals¶ New in version 2.6.
Compares two or more arrays and returns
trueif they have the same distinct elements andfalseotherwise.$setEqualshas 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: