Reputation: 137
I am performing a Mongodb collection.find using node.js, how do I return only the data without the column name into an array.
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"}
Upvotes: 4
Views: 52
Reputation: 4290
collection.find(...).toArray().map( function(u) { return u.title; } )
or
var result = []
collection.find().forEach(function(u) { result.push(u.title) })
Upvotes: 1