Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search using "near" seems to only return 100 results #12

Open
moowahaha opened this issue Nov 20, 2011 · 4 comments
Open

Search using "near" seems to only return 100 results #12

moowahaha opened this issue Nov 20, 2011 · 4 comments

Comments

@moowahaha
Copy link

For some reason, no matter how many matching documents I should have, I'm always getting max 100 results back.

where(
      :coordinates.near(:sphere) => {
          point: [some_longitude, some_latitude],
          max: search_radius,
          unit: :km
      }
).limit(9999).count #=> 100

A bit of reading reveals that the MongoDB Geospatial index will return 100 documents by default (http://www.mongodb.org/display/DOCS/Geospatial+Indexing). I can't seem to override it though. I'm looking into it now but thought I would raise it here in case somebody can figure it out before me.

FYI, I'm using mongoid_spacial 0.2.1, mongoid 2.3.3, mongo (gem) 1.4.0, MongoDB 1.8.2 & Ruby 1.9.3-p0.

@jtescher
Copy link

jtescher commented Apr 2, 2012

Same problem. Any resolution to this?

@moowahaha
Copy link
Author

I worked around it by using the "within" scope...

 where(
   :coordinates.within(:center) => {
     point: [some_longitude, some_latitude],
     max: search_radius,
     unit: :km
   }
 ).limit(9999).count #=> 9999

The downside is that results are not ordered by distance from a point but it is slightly more performant.

@jtescher
Copy link

jtescher commented Apr 3, 2012

Yeah that seems to work I guess.

@fltiago
Copy link

fltiago commented Aug 21, 2013

@moowahaha Do you ordered your element in some way? I'm using near only because the order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants