How to return only value of a field in mongodb
database, javascript, mongodb, nosql
Solution
Not sure what you language implementation is but the basic concept is:
var result = []
db.users.find().forEach(function(u) { result.push(u.text) })
And the returned value to `result` is:
["Hey","Hi","Hello","yes"]
Problem
After applying the find operation in mongodb.. i get the following list of documents.. ``` db.users.find(....) ``` i got: ``` { "text" : "Hey" } { "text" : "Hi" } { "text" : "Hello" } { "text" : "yes" } ``` How can i convert it into ``` ["Hey","Hi","Hello","yes"]. ``` i tried ``` db.users.find(...).map( function(u) { return "u.text"; } ) ``` but it is giving error!