本文介紹了如何在mongodb中只返回一個字段的值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
在 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中只返回一個字段的值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!