Re: [MongoMapper] Geospatial query limit?

254 views
Skip to first unread message

Jon Kern

unread,
Aug 21, 2012, 2:05:11 PM8/21/12
to mongo...@googlegroups.com
This seems to be a MongoDB default

http://www.mongodb.org/display/DOCS/Geospatial+Indexing/#GeospatialIndexing-Querying

Can you confirm that you can get desired results from the mongo console without using MongoMapper, and therefore isolate the problem to MongoMapper?
jon

blog: http://technicaldebt.com
twitter: http://twitter.com/JonKernPA
Stuart Harrison said the following on 8/17/12 10:41 AM:
Hi,

Have been working with MongoMapper for a few weeks now, and seem to have hit a known issue with geospatial queries being limited to 100 results. After reading arounf a bit I thought 'no problem, I'll just add my own limit at the end of the query', but even this doesn't seem to work. Here's what I've got so far:

EARTH_RADIUS_M = 3959
query[:latlng] = {'$nearSphere' => [lat, lng], '$maxDistance' => Float(distance_in_miles.to_i) / EARTH_RADIUS_M }

Now, no matter what limit I put on the end, I seem to get 100, e.g:

applications = Application.where(query).count 
=> 100
applications = Application.where(query).limit(50).count
=> 100
applications = Application.where(query).limit(10000).count
=> 100
applications = Application.where(query).limit(10).count
=> 100

Any ideas?

Cheers

--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en

Stuart Harrison

unread,
Aug 28, 2012, 10:42:38 AM8/28/12
to mongo...@googlegroups.com
Ah, apologies, I missed this reply. Yup, it's the same in the Mongo console. I've managed to work around this by using $within and $centerSphere, which has no limit, like so:

query[:latlng] = {'$within' => {'$centerSphere' => [[mapit["lat"], mapit["lng"]], Float(params[:within].to_i) / EARTH_RADIUS_M ] }}

Cheers

Phill Booth

unread,
Feb 16, 2017, 6:08:14 AM2/16/17
to MongoMapper
I think the asynchronous code is hitting the db.close(); before the .each loop finished, for some reason everyone is getting only 100 results, so here is a work-around.
 

var url = 'mongodb://localhost:27017/mydb';


  MongoClient.connect(url, function(err, db) {

       var i=0;

       var collection = db.collection('documents');

       collection.find().each(function(err, docs) {

         if (docs != null){

            console.log(docs);
            console.log(i);

            i++;

            if( i >= docs.length ){
              db.close();
            }

          }


  });


});



Reply all
Reply to author
Forward
0 new messages