如何解决我们如何在mongodb中使用near计算距离
请参考以下链接:next in mongodb。 我想计算我给出的坐标与文档中存在的坐标之间的距离。 我有以下查询
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},])
我也想用near来显示距离。或者还有其他方法可以计算距离吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。