我有以下查询语句,它根据经纬度使用mongoDB的"
2dsphere
"索引返回结果。然而,当我在聚合操作中使用相同的查询时,$maxDistance
无效,并且始终显示相同的结果。db.travelLocationSearch.find({
location: {
$near: {
$geometry: {
type: "Point",
coordinates: [-3.7037901999999576, 40.4167754] // madrid, spain
},
$maxDistance: (60*1609.344) // miles to meters
}
}
}).count()
60英里内的结果数-147
200英里内的结果数-170
500英里内的结果数-671
然而当我使用Mongo聚合来编写相同的查询时
db.travelLocationSearch.aggregate([
{
$geoNear: {
near: { type: "Point", coordinates: [ -3.7037901999999576, 40.4167754 ] },
distanceField: "dist.calculated",
maxDistance: (100 * 1609.34), // miles to meter
distanceMultiplier: 0.000621371, // meter to miles
includeLocs: "dist.location",
spherical: true
}
}
]).itcount()
在60英里内的结果数 - 100
在200英里内的结果数 - 100
在500英里内的结果数 - 100
我也按照这里解释的方式验证了我的查询($geoNear聚合忽略maxDistance)
下面是我的索引
> db.travelLocationSearch1.getIndexes()
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "zen.travelLocationSearch"
},
{
"v" : 2,
"key" : {
"location" : "2dsphere"
},
"name" : "location_2dsphere",
"ns" : "zenbrisa.travelLocationSearch1",
"2dsphereIndexVersion" : 3
}
]
请告诉我该如何解决。我的基本要求是使用给定的英里数和纬度、经度,随着用户增加英里数,结果会越来越多。