2016-11-16 85 views
2

我正在使用MongoDB Geospatial和node.js并且表示查询特定点附近的最近街道。 在我的结果中,我只想选择'名称'和'地址'的字段。 我试过下面的这段代码,但它不起作用,我得到这个错误:如何使用MongoDB地理空间选择查询中的字段?

“未处理的拒绝错误:无法使用$ select与Array。”

谢谢。

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

回答

0

好吧,发现:

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