我有一個包含這樣的文檔集合:
{
"_id" : "cysMrqjootq6YS6WP",
「profile」 : {
……
"deliveryDistance」 : 20,
"address" : {
"loc" : {
"type" : "Point",
"coordinates" : [
—2.120361,
52.536273
]
} }
}
}
而且我有一個GeoJSON的點,如:
var referencePoint= {
"type" : "Point",
"coordinates" : [
—2.120361,
52.536273
]
}
我使用Meteor.js,Node.js的和MongoDB。我想創建一個查詢,其中此點的maxDistance是每個文檔的deliveryDistance屬性到我的集合。
如果maxDistance是一個固定值,查詢將是:
myCollection.find({
「profile.address.loc":{
"$nearSphere": {
"$geometry": referencePoint,
"$maxDistance": 20000 //for 20Kms
}
}
})
但這種情況並非如此。對於每個文檔,maxDistance必須是「profile.deliveryDistance」的值。如何在此查詢中將文檔中的此值用作maxDistance?可能嗎?如果沒有,還有其他想法?
啊確定,聚合。非常感謝 :) –