$filter (aggregation)
On this page
Definition
Compatibility
You can use
$filter
for deployments hosted in the following
environments:
-
MongoDB Atlas : The fully managed service for MongoDB deployments in the cloud
-
MongoDB Enterprise : The subscription-based, self-managed version of MongoDB
-
MongoDB Community : The source-available, free-to-use, and self-managed version of MongoDB
Syntax
$filter
has the following syntax:
{ $filter: { input: <array>, cond: <expression>, as: <string>, limit: <number expression> } }
Field
|
Specification
|
---|---|
input
|
An
expression
that
resolves to an array.
|
cond
|
An
expression
that resolves
to a boolean value used to determine if an element should be
included in the output array. The expression references each
element of the
input
array individually with the variable
name specified in
as
.
|
as
|
Optional. A name for the
variable
that represents each
individual element of the
input
array. If no name is
specified, the variable name defaults to
this
.
|
limit
|
Optional. A number expression that restricts the number of matching
array elements that
If the specified
|