(1.8.x) geospatial query with limit of 200 or 10 always returns 100

11 views
Skip to first unread message

Keith Irwin

unread,
Jul 13, 2011, 4:39:49 PM7/13/11
to mongod...@googlegroups.com
Hi--

I've got this bit of code:

      val query = MongoDBObject("location" -> MongoDBObject("$near" -> (zipcode.longitude, zipcode.latitude)))
      val cursor = stuff.find(query).limit(200)
      println("CURSOR COUNT = " + cursor.count)

The result of the print is always "100" even though I have millions of objects in that collection.

The docs say: "Use limit() to specify a maximum number of points to return (a default limit of 100 applies if unspecified)."

Interestingly, if I use "10" for the limit in the above query, the println still emits "100".

Same thing when using the mongo cli:

   > var c = db.stuff.find({location: { $near : [-89, 45]}})
   > c.count()
   100
   > var c = db.stuff.find({location: { $near : [-89, 45]}}).limit(200)
   > c.count()
   100
   > var c = db.stuff.find({location: { $near : [-89, 45]}}).limit(20) 
   > c.count()                                                            
   100

Is there a bug in here somewhere?  (1.8.x)

HOWEVER, when I process the results of the query with .limit(200), I actually get 200 objects.

Keith

Bernie Hackett

unread,
Jul 13, 2011, 4:59:10 PM7/13/11
to mongodb-user
See https://jira.mongodb.org/browse/SERVER-739

count() doesn't take limit() into account with geo queries.
Reply all
Reply to author
Forward
0 new messages