我有一个查询,它使用聚合管道来检索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
}
]
答案 0 :(得分: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寻求解决方案的帮助。