Overcoming MapReduce Geospatial $near query default limit of 100

326 views
Skip to first unread message

David D.

unread,
Aug 10, 2011, 9:25:11 AM8/10/11
to mongodb-user
Hi,

I'm trying to do a MapReduce based on a query that looks something
like this:

query : {'ll' : {'$near': [40.702,-73.990], '$maxDistance': .01}}

The problem is that it seems $near has a default of 100 results (as
described here: http://www.mongodb.org/display/DOCS/Geospatial+Indexing#GeospatialIndexing-Querying)

When I execute the mapreduce, this limit is confirmed in the dbres
("counts":{"input":100,"emit":100,"output":4})

For a normal query, the documentation says to change the limit for a
$near query using dot notation find({'ll' : {'$near':
[40.702,-73.990], '$maxDistance': .01}}).limit(20). But how do we do
that with a map reduce? We can't simply append .limit() to the object
in the mapreduce command object (at least I get an error), and the
'limit' parameter of the mapreduce command has no effect on the $near
query.

So how do we get around the 100 limit for $near with a mapreduce?

Bernie Hackett

unread,
Aug 10, 2011, 2:27:13 PM8/10/11
to mongodb-user
There is a limit parameter for the mapreduce command but it doesn't
seem to help in this case. I've opened a server ticket for this issue:

https://jira.mongodb.org/browse/SERVER-3571

On Aug 10, 6:25 am, "David D." <da...@grandelabs.com> wrote:
> Hi,
>
> I'm trying to do a MapReduce based on a query that looks something
> like this:
>
> query : {'ll' : {'$near': [40.702,-73.990], '$maxDistance': .01}}
>
> The problem is that it seems $near has a default of 100 results (as
> described here:http://www.mongodb.org/display/DOCS/Geospatial+Indexing#GeospatialInd...)

David D.

unread,
Aug 11, 2011, 9:20:10 AM8/11/11
to mongodb-user
Thanks, this is really important if what you're trying to do is count
a lot of data that might be nearby...maybe the number of location-
based comments nearby, etc.
Reply all
Reply to author
Forward
0 new messages