On this page本页内容
$setEquals¶Compares two or more arrays and returns 比较两个或多个数组,如果它们具有相同的不同元素,则返回true if they have the same distinct elements and false otherwise.true,否则返回false。
$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将忽略重复项。$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.$setEquals不会下降到嵌套数组中,而是在顶层计算数组。
| Result | |
|---|---|
{ $setEquals: [ [ "a", "b", "a" ], [ "b", "a" ] ] } |
true |
{ $setEquals: [ [ "a", "b" ], [ [ "a", "b" ] ] ] } |
false |
Consider an 考虑一个包含以下文档的experiments collection with the following documents:experiments集合:
The following operation uses the 以下操作使用$setEquals operator to determine if the A array and the B array contain the same elements:$setEquals运算符确定A数组和B数组是否包含相同的元素:
The operation returns the following results:操作返回以下结果: