On this page本页内容
$setEquals
¶Compares two or more arrays and returns true
if they have the same distinct elements and false
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.有关表达式的详细信息,请参阅表达式。
$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.
Result | ||
---|---|---|
{ $setEquals: [ [ "a", "b", "a" ], [ "b", "a" ] ] } |
true | |
{ $setEquals: [ [ "a", "b" ], [ [ "a", "b" ] ] ] } |
false |
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:操作返回以下结果: