2016-08-18 141 views
0

我有一个查询使用聚合管道检索200英里半径内的所有记录。但是,查询只返回156个记录中的100个。我不确定问题是什么。我在这个线程中包含了查询。非常感谢任何反馈和帮助。

pRadius = ((pRadius * Math.PI)/180)*3963.2*69; 

    return new Promise(function(fullfill, reject){ 

     Offers.aggregate(
      [ 
       { 
        $geoNear: { 
         near: { type: "Point", coordinates: [parseFloat(pLatLngArray[0]), parseFloat(pLatLngArray[1])] }, 
         distanceField: "dist", 
         spherical: true, 
         maxDistance: parseFloat(pRadius), 
         query: { 
          $and: 
           [ 
            { type_id: {$in: pTypeIDArray } }, 
            { valid: true } , 
            { $or: [ { enddate: null }, { enddate: { $gte: new Date() } } ] } 
           ] 
         }, 
        } 
       }, 
       { 
        $project : { 
         provider_id : 1 
         , providername: 1 
         , offer_id: 1 
         , title: 1 
         , description: 1 
         , additionalinfo: 1 
         , likecount: 1 
         , restrictions: 1 
         , imagepath: 1 
         , price: 1 
         , startdate: 1 
         , enddate: 1 
         , showrating: 1 
         , dist: 1 
         , logopath: 1 
         , _id: 0 
        } 
       }, 
       { 
        $skip: Number(pStartIndex) 
       }, 
       { 
        $limit: Number(pEndIndex) 
       }, 
      ]).exec().then(function(result){ 
       fullfill(result); 
      }).catch(function(err){ 
       reject(err); 
      }); 
    }); 

该文件有以下指标定义:

db.offers.getIndexes() 
[ 
{ 
    "v" : 1, 
    "key" : { 
     "_id" : 1 
    }, 
    "name" : "_id_", 
    "ns" : "medmart_db.offers" 
}, 
{ 
    "v" : 1, 
    "key" : { 
     "loc" : "2dsphere" 
    }, 
    "name" : "loc_2dsphere", 
    "ns" : "medmart_db.offers", 
    "background" : true, 
    "2dsphereIndexVersion" : 2 
}, 
{ 
    "v" : 1, 
    "key" : { 
     "loc" : "2d" 
    }, 
    "name" : "loc_2d", 
    "ns" : "medmart_db.offers", 
    "background" : true 
} 
] 

回答

1

所以解决方法是设置一个更高的回报率限制到汇聚管道。

return new Promise(function(fullfill, reject){ 

    Offers.aggregate(
     [ 
      { 
       $geoNear: { 
        near: { type: "Point", coordinates: [parseFloat(pLatLngArray[0]), parseFloat(pLatLngArray[1])] }, 
        distanceField: "dist", 
        spherical: true, 
        maxDistance: parseFloat(pRadius), 
        limit: 999999, // set the limit here 
        query: { 
         $and: 
          [ 
           { type_id: {$in: pTypeIDArray } }, 
           { valid: true } , 
           { $or: [ { enddate: null }, { enddate: { $gte: new Date() } } ] } 
          ] 
        }, 
       } 
      }, 
      { 
       $project : { 

感谢JP寻求解决方案。