2016-11-16 38 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}) 
相關問題