1
我有以下查询返回基于经度和纬度的结果使用“2dsphere
”索引mongoDB查找(),但是当我使用相同的查询聚合$maxDistance
不工作,并始终显示相同的结果。 147
上200英里 - -
db.travelLocationSearch.find({
location: {
$near: {
$geometry: {
type: "Point",
coordinates: [-3.7037901999999576, 40.4167754] // madrid, spain
},
$maxDistance: (60*1609.344) // miles to meters
}
}
}).count()
结果上60英里计数671
然而,当我使用蒙戈骨料
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()
结果计数写相同的查询 - 上500英里170
在60英里 - 100
对200英里 - 100
对500英里 - 100
我也验证了我的查询如下解释($geoNear aggregation ignoring 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
}
]
请让我知道solution.My基本要求是利用赋给英里,纬度,经度和用户使用结果增加英里结果变得越来越长。