Return data only to an array

I am assembling Mongodb collection.find using node.js, how can I return only data without a column name to 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"}
+4
source share
1 answer
collection.find(...).toArray().map( function(u) { return u.title; } )

or

var result = []
collection.find().forEach(function(u) { result.push(u.title) })
+1
source

Source: https://habr.com/ru/post/1619055/


All Articles