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. $setIntersection ignores the order of the elements.
$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.
| Result | |
|---|---|
Consider an experiments collection with the following documents:
The following operation uses the $setIntersection operator to return an array of elements common to both the A array and the B array:
The operation returns the following results:操作返回以下结果: