【问题标题】:Aggregation is not working with the $geoNear聚合不适用于 $geoNear
【发布时间】:2021-03-26 12:27:36
【问题描述】:

当我将聚合函数与以下管道一起使用时,我遇到了一些非常奇怪的事情:

[
  {
    $geoNear: {
      near: [6.0950994999999999, 49.8914114000000026],
      distanceField: 'distance',
    },
  },
]

这是我在调用聚合函数时得到的:

$geoNear 仅作为管道中的第一阶段有效。

我开启了猫鼬调试模式mongoose.set('debug', true);

这就是我在日志中得到的内容

Mongoose: liveRestaurants.aggregate([ { '$geoNear': { near: [ 6.0950995, 49.8914114 ], distanceField: 'distance' } }], {})

其实是在第一条时间线。

有什么办法解决这个问题吗?

【问题讨论】:

    标签: javascript node.js mongodb mongoose


    【解决方案1】:

    你能不能这样试一试,

    [
    {
        $geoNear: {
        near: {
            'type': 'Point',
            'coordinates': [6.0950994999999999, 49.8914114000000026]
        },
        distanceField: 'distance'
        },
    },
    ]
    

    【讨论】:

    • 我发现了这个问题,我将在单独的线程中回答。谢谢
    猜你喜欢
    • 2013-04-29
    • 2014-08-09
    • 2023-03-21
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多