【问题标题】:How can I select the fields in the query with MongoDB Geospatial?如何使用 MongoDB 地理空间选择查询中的字段?
【发布时间】:2017-03-30 01:08:23
【问题描述】:

我将 MongoDB Geospatial 与 node.js 一起使用,并表示查询特定点附近最近的街道。 在我的结果中,我只想选择“名称”和“地址”字段。 我在下面尝试了这段代码,但它不起作用,我收到了这个错误:

“未处理的拒绝错误:不能将 $select 与 Array 一起使用。”

谢谢。

Street.find({
    'location': {
        $near: {
            $geometry: {
                type: 'Point',
                coordinates: coords
            },
            $maxDistance: 1000
        },
        $select: {
            _id: 0,
            name: 1,
            address: 1
        }
    }
})

【问题讨论】:

    标签: node.js mongodb express geospatial


    【解决方案1】:

    好的,找到了:

    Street.find(
        {
            'location': {
                $near: {
                    $geometry: {type: 'Point', coordinates: coords},
                    $maxDistance: 1000
                }
            }
        })
        .select({'_id': 0, 'name': 1, 'address': 1})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-07
      • 1970-01-01
      • 2019-01-30
      • 1970-01-01
      • 2019-09-23
      • 2014-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多