Repro steps
Using the schema defined in the testfile
jstests/aggregation/accumulators/min_n_max_n.js
Do this
coll.aggregate([ {$group: {_id: '$state', maxSales: {$maxN: {output: '$sales', n: NumberDecimal("18446744073709551615")}}}}, {$sort: {_id: 1}} ])
uncaught exception: Error: command failed:
{
"ok" : 0,
"errmsg" : "PlanExecutor error during aggregation :: caused by :: Value for 'n' must be of integral type, but found 18446744073709551615",
"code" : 5787903,
"codeName" : "Location5787903"
}
with original command request: {
"aggregate" : "min_n_max_n",
"pipeline" : [
{
"$group" : {
"_id" : "$state",
"maxSales" : {
"$maxN" :
{
"output" : "$sales",
"n" : NumberDecimal("18446744073709551615")
}
}
}
},
{
"$sort" :
{
"_id" : 1
}
}
],
"cursor" : {
},
"lsid" :
{
"id" : UUID("36f8c6e2-3d73-49e0-9729-87a97454392f")
}
} on connection: connection to 127.0.0.1:27017 : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:24:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:737:17
assert.commandWorked@src/mongo/shell/assert.js:829:16
DB.prototype._runAggregate@src/mongo/shell/db.js:280:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:970:12
@(shell):1:1
>
If I use max signed int64, I don't get the error, but if I add 1 to it, I get back the error.
coll.aggregate([ {$group: {_id: '$state', maxSales: {$maxN: {output: '$sales', n: NumberDecimal("9223372036854775807")}}}}, {$sort: {_id: 1}} ])
{ "_id" : "CA", "maxSales" : [ 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100 ] }
{ "_id" : "NY", "maxSales" : [ 700, 600, 500, 400, 300, 200, 100 ] }
{ "_id" : "TX", "maxSales" : [ 400, 300, 200, 100 ] }
> coll.aggregate([ {$group: {_id: '$state', maxSales: {$maxN: {output: '$sales', n: NumberDecimal("9223372036854775808")}}}}, {$sort: {_id: 1}} ])
uncaught exception: Error: command failed:
{
"ok" : 0,
"errmsg" : "PlanExecutor error during aggregation :: caused by :: Value for 'n' must be of integral type, but found 9223372036854775808",
"code" : 5787903,
"codeName" : "Location5787903"
}
with original command request: {
"aggregate" : "min_n_max_n",
"pipeline" : [
{
"$group" : {
"_id" : "$state",
"maxSales" : {
"$maxN" :
{
"output" : "$sales",
"n" : NumberDecimal("9223372036854775808")
}
}
}
},
{
"$sort" :
{
"_id" : 1
}
}
],
"cursor" : {
},
"lsid" :
{
"id" : UUID("36f8c6e2-3d73-49e0-9729-87a97454392f")
}
} on connection: connection to 127.0.0.1:27017 : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:24:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:737:17
assert.commandWorked@src/mongo/shell/assert.js:829:16
DB.prototype._runAggregate@src/mongo/shell/db.js:280:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:970:12
@(shell):1:1
>