Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb not returning more than 100 records

Tags:

mongodb

Below is the Mongo query I am using, but this is returning 100 as max records even if I increase the maxDistance to the maximum possible value. I know there are lot of records mongo is not returning, value more than 15 miles as a maxDistance its always returning 100 documents , please help.

db.business.aggregate([ 
{ "$geoNear" : { 
    "maxDistance" : 0.005046438589510322, --this is 15 miles
    "distanceMultiplier" : 3963.191 , 
    "near" : [ -84.464374 , 33.864826] , 
    "spherical" : true , 
    "distanceField" : "distance",
    query: {
                "category": { "$eq": "restaurant" } 
            }
    }
 } ,  
    { "$match" : { "status" : { "$in" : [ "active"]}}}, {
    $group: {
      _id : null, 
      count : {$sum : 1}
    }
  }
 ])
like image 377
Sam Avatar asked Jan 30 '23 23:01

Sam


1 Answers

You should add limit, otherwise it uses the default which is to return the first 100 documents:

{ "$geoNear" : { 
    "maxDistance" : 0.005046438589510322, --this is 15 miles
    "limit" 1000,
    ...

The above will return 1,000 documents

like image 107
Ori Dar Avatar answered Feb 12 '23 10:02

Ori Dar