Details
-
Bug
-
Resolution: Fixed
-
Major - P3
-
None
-
None
Description
Looks like there's a typo in the "Behavior" section of the reference page for the $filter agg expression: https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/#behavior
The second two examples are the following:
// The docs claim this will return [ 1, 2, 3.1, NumberLong(4) ].
|
{
|
$filter: {
|
input: [ 1, "a", 2, null, 3.1, NumberLong(4), "5" ],
|
as: "num",
|
cond: { $and:[
|
{ $gte: [ "$$num", NumberLong("-9223372036854775807") ] },
|
{ $gte: [ "$$num", NumberLong("9223372036854775807") ] }
|
] }
|
limit: 2
|
}
|
}
|
|
|
// The docs claim this will return [ 1 ].
|
{
|
$filter: {
|
input: [ 1, "a", 2, null, 3.1, NumberLong(4), "5" ],
|
as: "num",
|
cond: { $and:[
|
{ $gte: [ "$$num", NumberLong("-9223372036854775807") ] },
|
{ $gte: [ "$$num", NumberLong("9223372036854775807") ] }
|
] }
|
limit: { $add: [ 0, 1 ]}
|
}
|
}
|
I think the second $gte should be a $lte for both example expressions? Also, both are missing a comma after the cond expression. So they should look like this:
// The docs claim this will return [ 1, 2, 3.1, NumberLong(4) ].
|
{
|
$filter: {
|
input: [ 1, "a", 2, null, 3.1, NumberLong(4), "5" ],
|
as: "num",
|
cond: { $and:[
|
{ $gte: [ "$$num", NumberLong("-9223372036854775807") ] },
|
{ $lte: [ "$$num", NumberLong("9223372036854775807") ] }
|
] },
|
limit: 2
|
}
|
}
|
|
|
{
|
$filter: {
|
input: [ 1, "a", 2, null, 3.1, NumberLong(4), "5" ],
|
as: "num",
|
cond: { $and:[
|
{ $gte: [ "$$num", NumberLong("-9223372036854775807") ] },
|
{ $lte: [ "$$num", NumberLong("9223372036854775807") ] }
|
] },
|
limit: { $add: [ 0, 1 ]}
|
}
|
}
|