geospatial - MongoDB $near Returning Max Results with Max Distance -


i have following mongo query (written in php)

 $q = array("created_at" => array("\$gte" => $mdate), "icv" => 1, "loc" => array("\$near" => array($latitude, $longitude), "\$maxdistance" => 5)); 

which basically:

db.collection.find({loc: {$near: [xx,yy]}, $maxdistance: 5}, "vid": 1, "created_at":{$gte: "somedate"}}); 

i find documents match query, not 100 returns default. if set limit on query, goes out side distance distance.

any suggestions?

in this mailing list post, eliot mentions $near not use cursor, results limited either 4mb or 100 documents, whichever reached first. current documentation says same, true 2d indexes (the documentation should fixed docs-1841).

if storing points in geojson , using 2dsphere indexes (new in version 2.4), $near queries utilize cursors , should not have hard upper limit of 100 documents.

consider following examples, first using 2d index:

> var point = [0,0]; > for(i=0;i<200;i++) db.foo.insert({x: point}); > db.foo.ensureindex({x: "2d"}); > db.foo.find({x: {$near: point}}).count(true); 100 > db.foo.find({x: {$near: point}}).limit(200).count(true); 100 

then using 2dsphere index equivalent point data:

> var point = {type: "point", coordinates: [0,0]}; > for(i=0;i<200;i++) db.bar.insert({x: point}); > db.bar.ensureindex({x: "2dsphere"}) > db.bar.find({x: {$near: point}}).count(true) 200 > db.bar.find({x: {$near: point}}).limit(150).count(true) 150 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -