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基本要求是利用賦給英里,緯度,經度和用戶使用結果增加英里結果變得越來越長。