在 mongodb 中应用查找操作后..我得到以下文档列表..
After applying the find operation in mongodb.. i get the following list of documents..
db.users.find(....)
我明白了:
{ "text" : "Hey" }
{ "text" : "Hi" }
{ "text" : "Hello" }
{ "text" : "yes" }
如何转换成
["Hey","Hi","Hello","yes"].
我试过了
db.users.find(...).map( function(u) { return "u.text"; } )
但它给出了错误!
不确定你的语言实现是什么,但基本概念是:
Not sure what you language implementation is but the basic concept is:
var result = []
db.users.find().forEach(function(u) { result.push(u.text) })
而result
的返回值为:
["Hey","Hi","Hello","yes"]
这篇关于如何在mongodb中只返回一个字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!