首頁  >  問答  >  主體

mongodb 針對某列值傳回list

雷雷
迷茫迷茫2727 天前570

全部回覆(1)我來回復

  • PHP中文网

    PHP中文网2017-05-02 09:20:50

    mongodb 支援js語法,所以直接用map就可以了

    // es6 
    db.collection.find({}, {'name': 1}).map( x => x.name ) // [ "a", "b", "c" ]
    
    db.collection.find({}, {'name': 1}).map(function(x) {return x.name} ) 

    map介紹請看 https://danmartensen.svbtle.com/javascripts-map-reduce-and-filter#map_1

    回覆
    0
  • 取消回覆