On this page本页内容
$filter
¶New in version 3.2.版本3.2中的新功能。
Selects a subset of an array to return based on the specified condition. 根据指定的条件选择要返回的数组子集。Returns an array with only those elements that match the condition. The returned elements are in the original order.返回仅包含与条件匹配的元素的数组。返回的元素按原始顺序排列。
$filter
has the following syntax:语法如下所示:
input |
|
as |
input array. this .this 。 |
cond |
input array individually with the variable name specified in as .as 中指定的变量名分别引用input 数组的每个元素。 |
For more information on expressions, see Expressions.有关表达式的详细信息,请参阅表达式。
[ 1, 2, 3.1, NumberLong(4) ] |
A collection 集合sales
has the following documents:sales
包含以下文档:
The following example filters the 以下示例筛选items
array to only include documents that have a price
greater than or equal to 100
:items
数组,使其仅包含price
大于或等于100
的文档:
The operation produces the following results:该操作将产生以下结果: