仅将数据返回到数组中
我正在使用node.js执行一个Mongodb的collection.find,我如何只返回没有列名的数据到数组中。
var cursor = collection.find( { title: title }, { title: 1, _id: 0 }); cursor.sort( { title: 1 }); cursor.toArray(function (err, all_documents) { .... });
{"title":"MongoDB Overview"} {"title":"NoSQL Overview"} {"title":"Tutorials Point Overview"}
collection.find(...).toArray().map( function(u) { return u.title; } )
要么
var result = [] collection.find().forEach(function(u) { result.push(u.title) })