[SERVER-13486] The geoNear command can create too large BSON objects Created: 04/Apr/14  Updated: 11/Jul/16  Resolved: 09/Apr/14

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 2.6.0-rc1, 2.6.0-rc2
Fix Version/s: 2.6.1, 2.7.0

Type: Bug Priority: Major - P3
Reporter: giuliano giuffrida Assignee: hari.khalsa@10gen.com
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Operating System: ALL
Backport Completed:
Steps To Reproduce:

for (var i = 1; i <= 200000; i++) db.testData.insert( { loc :

{type:"Point", coordinates:[90*(i/200000),90*(i/200000)]}

} )

db.testData.ensureIndex(

{loc : "2dsphere"}

)

db.testData.aggregate([{$geoNear: {near :

{ type : "Point" , coordinates: [50,50] }

, distanceField:"dist",spherical : true, maxDistance : (10000000), num:200000 }}])

Participants:

 Description   
Issue Status as of April 15, 2014

ISSUE SUMMARY
The geoNear command does not check if the BSON size limit is reached when assembling the result array.

USER IMPACT
Results from geoNear that are larger than the BSON size (16MB) cause an exception and abort the command.

WORKAROUNDS
Query for a smaller result set, for example with a smaller maxDistance value.

RESOLUTION
The geoNear command now detects when it reaches the BSON size and will truncate the result set. A warning is logged that the command tried to return a larger result.

AFFECTED VERSIONS
Version 2.6.0 is affected by this bug.

PATCHES
The patch is included in the 2.6.1 production release.

Original description

The new aggregation framework on 2.6.0 returns a cursor, so its output should be unlimited.
However if one performs an aggregation query with $geonear it looks like the output is still limited to 16MB.

> db.testData.aggregate([{$geoNear: {near :

{ type : "Point" , coordinates: [50,50] }

, distanceField:"dist",spherical : true, maxDistance : (10000000), num:200000 }}])
assert: command failed: {
"errmsg" : "exception: nextSafe():

{ $err: \"BSONObj size: 23689189 (0x16977E5) is invalid. Size must be between 0 and 16793600(16MB)\", code: 10334 }

",
"code" : 13106,
"ok" : 0
} : aggregate failed
Error: command failed: {
"errmsg" : "exception: nextSafe():

{ $err: \"BSONObj size: 23689189 (0x16977E5) is invalid. Size must be between 0 and 16793600(16MB)\", code: 10334 }

",
"code" : 13106,
"ok" : 0
} : aggregate failed
at Error (<anonymous>)
at doassert (src/mongo/shell/assert.js:11:14)
at Function.assert.commandWorked (src/mongo/shell/assert.js:244:5)
at DBCollection.aggregate (src/mongo/shell/collection.js:1149:12)
at (shell):1:13
2014-04-04T11:17:26.395+0200 Error: command failed: {
"errmsg" : "exception: nextSafe():

{ $err: \"BSONObj size: 23689189 (0x16977E5) is invalid. Size must be between 0 and 16793600(16MB)\", code: 10334 }

",
"code" : 13106,
"ok" : 0
} : aggregate failed at src/mongo/shell/assert.js:13



 Comments   
Comment by giuliano giuffrida [ 23/Apr/14 ]

"The geoNear command does not check if the BSON size limit is reached when assembling the result array."

I don't understand: why a "result array" and not a cursor ?
It looks like aggregation queries with geoNear are different from other aggregation queries, is that the case ?

Comment by Githook User [ 09/Apr/14 ]

Author:

{u'username': u'hkhalsa', u'name': u'Hari Khalsa', u'email': u'hkhalsa@10gen.com'}

Message: SERVER-13486 check obj size when building return of geonear cmd

(cherry picked from commit b4a2cc96b18cacdfece81215d9d8c7a3a84ba20a)
Branch: v2.6
https://github.com/mongodb/mongo/commit/ac55e3f5a963f8ed2b0516703f8305e8091595f0

Comment by Githook User [ 08/Apr/14 ]

Author:

{u'username': u'hkhalsa', u'name': u'Hari Khalsa', u'email': u'hkhalsa@10gen.com'}

Message: SERVER-13486 check obj size when building return of geonear cmd
Branch: master
https://github.com/mongodb/mongo/commit/b4a2cc96b18cacdfece81215d9d8c7a3a84ba20a

Generated at Thu Feb 08 03:31:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.