How do I limit geo search ($near quer

458 views
Skip to first unread message

Abe

unread,
Oct 10, 2010, 5:19:12 AM10/10/10
to mongodb-user
Hello! My name is Abe and I think MongoDB is absolutely awesome!

I have been using MongoDB in my production environment at work and
recently I have been working on implementing a store finder service
in .Net with MongoDB.
I store a collection of store objects, where each store object
contains the latitude, longitude and zip code.

I have been following the documention on Geospacial Indexing (http://
www.mongodb.org/display/DOCS/Geospatial+Indexing) and was able to
implement the following services:

So, I am able to find the list of stores closest to a given zip code
by using the $near operator in my queries, but how do I limit the
results by a search radius?

Example:
Find me the closest stores to the zip code 90232 with a search radius
of 5 miles.

I am currently using version 1.6.3.
Is there an parameter for max distance in the $near operator and can I
use the unit in miles?

Thank you!

Eliot Horowitz

unread,
Oct 10, 2010, 9:45:51 AM10/10/10
to mongod...@googlegroups.com
db.places.find( { loc : { $near : [50,50] , $maxDistance : 5 } } )

Just made the docs a bit clearer as wel

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

thecleanmachine

unread,
Oct 10, 2010, 3:06:35 PM10/10/10
to mongodb-user
Also, I believe this will work by using a third parameter in the array
like this:

db.places.find( { loc : { $near : [50,50,5]} } )

Abe

unread,
Oct 11, 2010, 5:45:14 PM10/11/10
to mongodb-user
Thank you so much! This is just what I was looking for.
I tried using $within and $center, but since the results were getting
streamed, I was not able to get the sorted result set.

I saw your comments on http://jira.mongodb.org/browse/SERVER-813, but
I wasn't sure what the unit was.
Thanks again for updating the documentation as well.


On Oct 10, 6:45 am, Eliot Horowitz <eliothorow...@gmail.com> wrote:
> db.places.find( { loc : { $near: [50,50] , $maxDistance : 5 } } )
>
> Just made the docs a bit clearer as wel
>
> On Sun, Oct 10, 2010 at 5:19 AM, Abe <abecp...@gmail.com> wrote:
> > Hello! My name is Abe and I think MongoDB is absolutely awesome!
>
> > I have been using MongoDB in my production environment at work and
> > recently I have been working on implementing a store finder service
> > in .Net with MongoDB.
> > I store a collection of store objects, where each store object
> > contains the latitude, longitude and zip code.
>
> > I have been following the documention on Geospacial Indexing (http://
> >www.mongodb.org/display/DOCS/Geospatial+Indexing) and was able to
> > implement the following services:
>
> > So, I am able to find the list of stores closest to a given zip code
> > by using the $nearoperator in my queries, but how do I limit the
> > results by a searchradius?
>
> > Example:
> > Find me the closest stores to the zip code 90232 with a searchradius
> > of 5 miles.
>
> > I am currently using version 1.6.3.
> > Is there an parameter for max distance in the $nearoperator and can I

Abe

unread,
Oct 11, 2010, 5:45:23 PM10/11/10
to mongodb-user
Thank you!

On Oct 10, 12:06 pm, thecleanmachine <thecleanmach...@gmail.com>
wrote:
> Also, I believe this will work by using a third parameter in the array
> like this:
>
> db.places.find( { loc : { $near: [50,50,5]} } )
>
> On Oct 10, 6:45 am, Eliot Horowitz <eliothorow...@gmail.com> wrote:
>
> > db.places.find( { loc : { $near: [50,50] , $maxDistance : 5 } } )
>
> > Just made the docs a bit clearer as wel
>
> > On Sun, Oct 10, 2010 at 5:19 AM, Abe <abecp...@gmail.com> wrote:
> > > Hello! My name is Abe and I think MongoDB is absolutely awesome!
>
> > > I have been using MongoDB in my production environment at work and
> > > recently I have been working on implementing a store finder service
> > > in .Net with MongoDB.
> > > I store a collection of store objects, where each store object
> > > contains the latitude, longitude and zip code.
>
> > > I have been following the documention on Geospacial Indexing (http://
> > >www.mongodb.org/display/DOCS/Geospatial+Indexing) and was able to
> > > implement the following services:
>
> > > So, I am able to find the list of stores closest to a given zip code
> > > by using the $nearoperator in my queries, but how do I limit the
> > > results by a searchradius?
>
> > > Example:
> > > Find me the closest stores to the zip code 90232 with a searchradius
> > > of 5 miles.
>
> > > I am currently using version 1.6.3.
> > > Is there an parameter for max distance in the $nearoperator and can I
Reply all
Reply to author
Forward
0 new messages