我们如何在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 (将#修改为@)