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