[SERVER-813] Add radius to $near Created: 23/Mar/10  Updated: 12/Jul/16  Resolved: 01/Apr/10

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 1.3.4
Fix Version/s: 1.5.0

Type: Improvement Priority: Minor - P4
Reporter: pitchfork media, inc Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All


Backwards Compatibility: Minor Change
Participants:

 Description   

add a radius parameter to $near to prevent sparsely populated regions from sucking in objects from areas nowhere nearby.

example: http://dpaste.com/175056/.
in this example, the results include two events from alaska (correct), and one from austin, tx.



 Comments   
Comment by Eliot Horowitz (Inactive) [ 11/Oct/10 ]

No - its in radians - so 1 ~ 69 miles

Comment by Abe Park [ 11/Oct/10 ]

@Eliot: assert.gt( 3 , a( t.find( { loc :

{ $near : [ 50 , 50 ] , $maxDistance : 3 }

} ).limit(50) ) , "C3" )

is the distance value 3 in miles?

Comment by Eliot Horowitz (Inactive) [ 26/Apr/10 ]

in a release

Comment by auto [ 01/Apr/10 ]

Author:

{'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: $maxDistance for $near SERVER-813
http://github.com/mongodb/mongo/commit/9c8fa4b93548c6c6e1113e9b66d2400e3eacfdd1

Comment by Eliot Horowitz (Inactive) [ 01/Apr/10 ]

assert.lt( 3 , a( t.find( { loc :

{ $near : [ 50 , 50 ] }

} ).limit(50) ) , "C1" )
assert.gt( 3 , a( t.find( { loc :

{ $near : [ 50 , 50 , 3 ] }

} ).limit(50) ) , "C2" )
assert.gt( 3 , a( t.find( { loc :

{ $near : [ 50 , 50 ] , $maxDistance : 3 }

} ).limit(50) ) , "C3" )

Comment by auto [ 01/Apr/10 ]

Author:

{'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: first cut at radius limiting $near SERVER-813
http://github.com/mongodb/mongo/commit/fc7f36ad702fc1b45b17b0e1d08586c8faf77a72

Comment by auto [ 01/Apr/10 ]

Author:

{'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: first cut at radius limiting $near SERVER-813
http://github.com/mongodb/mongo/commit/1e3abf89b90bef04b0d8ce601a60860dc31c632a

Comment by pitchfork media, inc [ 23/Mar/10 ]

code example w/o dpaste's fancy formatting:

from datetime import datetime, timedelta
import pprint
from pymongo import *

db = Connection().geotest
db.events.ensure_index([("location", GEO2D)])

db.events.insert(

{'title': "Juneau Celebration @ Downtown", 'location': [58.3019444, -134.4197222]}

)
db.events.insert(

{'title': "Something At Last Chance Mining Museum", 'location': [58.30782048987055, -134.40048336982727]}

)
db.events.insert(

{'title': "Free Grub @ Stubbs BBQ, Austin TX", 'location': [30.267153, -97.7430608]}

)

events = db.events.find({'location': {'$near': [58.30509234132916,
-134.42124366760254]}})
pprint.pprint([e['title'] for e in events])

results = [u'Juneau Celebration @ Downtown', # very close
u'Something At Last Chance Mining Museum', # within walking distance
u'Free Grub @ Stubbs BBQ, Austin TX'] # nowhere near juneau

db.drop_collection("events")

Generated at Thu Feb 08 02:55:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.