请参考以下链接:mongodb 中的 next。我想计算我给出的坐标与文档中存在的坐标之间的距离。我有以下查询
db.hotels.aggregate([
{
$search: {
index:'searchIndex', //index name
compound: {
must: {
text: {
query:'sun',
path:['name','address.landmark','address.city','address.state','address.country'],
fuzzy: {
maxEdits:2,
prefixLength: 3,
},
},
},
should: {
near:{
origin: {
type: 'Point',
coordinates: [-122.45665489904827,37.75118012951178],
},
pivot: 1000,
path: 'location' // how can I calculate distance too here?
},
}
}
}
},
{
$project: {
_id: 1,
name: 1,
address:1,
score: { $meta: "searchScore" }
}
},
{$limit:100},
])
我也想用近来显示距离。还是有另一种方法可以计算距离?