[SERVER-14366] geoNear should not allow $natural Created: 26/Jun/14  Updated: 11/Jul/16  Resolved: 27/Jun/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.3
Fix Version/s: 2.7.3

Type: Bug Priority: Minor - P4
Reporter: David Storch Assignee: David Storch
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

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

> t.drop()
> t.ensureIndex({a: "2dsphere"})
> t.save({a: {type: "Point", coordinates: [3, 4]}})
> t.save({a: {type: "Point", coordinates: [1, 2]}})
> t.find({a: {$near: {$geometry: {type: "Point", coordinates: [1, 2]}}}})
{ "_id" : ObjectId("53ac81a37616f382be9e6fdb"), "a" : { "type" : "Point", "coordinates" : [ 1, 2 ] } }
{ "_id" : ObjectId("53ac81a07616f382be9e6fda"), "a" : { "type" : "Point", "coordinates" : [ 3, 4 ] } }
> t.find({a: {$near: {$geometry: {type: "Point", coordinates: [1, 2]}}}}).hint({$natural: 1})
{ "_id" : ObjectId("53ac81a07616f382be9e6fda"), "a" : { "type" : "Point", "coordinates" : [ 3, 4 ] } }
{ "_id" : ObjectId("53ac81a37616f382be9e6fdb"), "a" : { "type" : "Point", "coordinates" : [ 1, 2 ] } }
> t.find({a: {$near: {$geometry: {type: "Point", coordinates: [1, 2]}}}}).sort({$natural: 1})
{ "_id" : ObjectId("53ac81a07616f382be9e6fda"), "a" : { "type" : "Point", "coordinates" : [ 3, 4 ] } }
{ "_id" : ObjectId("53ac81a37616f382be9e6fdb"), "a" : { "type" : "Point", "coordinates" : [ 1, 2 ] } }

Participants:

 Description   

Geo $near queries should always return results sorted by increasing distance from the query point. However, we handle $natural hint or sort before checking if there is a $near query. The result is that we end up doing a collection scan, hence returning results in the wrong order (see "Steps to Reproduce" for details).

A useful error is returned if $text is combined with $natural hint or $natural sort. We should do the same for geoNear.



 Comments   
Comment by Githook User [ 27/Jun/14 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-14366 disallow $natural sort or hint with geoNear
Branch: master
https://github.com/mongodb/mongo/commit/818302f1f1d9728e9a0688def022b8ea62f65544

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