et_phonehome
et_phonehome

Reputation: 137

Return data only into an array

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

Answers (1)

AlexD
AlexD

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

Related Questions