On this page本页内容
$setIntersection
¶Takes two or more arrays and returns an array that contains the elements that appear in every input array.获取两个或多个数组并返回一个数组,该数组包含每个输入数组中出现的元素。
$setIntersection
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.有关表达式的详细信息,请参阅表达式。
$setIntersection
performs set operation on arrays, treating arrays as sets. 对数组执行集合操作,将数组视为集合。If an array contains duplicate entries, 如果数组包含重复项,$setIntersection
ignores the duplicate entries. $SetCrossion
将忽略重复项。$setIntersection
ignores the order of the elements.$setIntersection
忽略元素的顺序。
$setIntersection
filters out duplicates in its result to output an array that contain only unique entries. 筛选掉结果中的重复项,以输出只包含唯一项的数组。The order of the elements in the output array is unspecified.未指定输出数组中元素的顺序。
If a set contains a nested array element, 如果集合包含嵌套数组元素,$setIntersection
does not descend into the nested array but evaluates the array at top-level.$setIntersection
不会下降到嵌套数组中,而是在顶层计算数组。
Consider an 考虑一个包含以下文档的experiments
collection with the following documents:experiments
集合:
The following operation uses the 以下操作使用$setIntersection
operator to return an array of elements common to both the A
array and the B
array:$setIntersection
运算符返回A
数组和B
数组共有的元素数组:
The operation returns the following results:操作返回以下结果: