[SERVER-61056] N from MaxN not accepting max uint64 , likely the same for the other "TopN" functions Created: 27/Oct/21  Updated: 27/Oct/23  Resolved: 28/Oct/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Steve La (Inactive) Assignee: Backlog - Query Execution
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-59590 Add test coverage verifying that 'n' ... Closed
Assigned Teams:
Query Execution
Operating System: ALL
Steps To Reproduce:

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
>

Participants:

 Description   

External Impact:
We expect user be able to provide max uint64 as N in MaxN and other function of the same family, but that returns an error.  It appears we can only go up to max signed int64


Generated at Thu Feb 08 05:51:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.