![](/img/trans.png)
[英]How to update an array of documents with an array of values in mongoDB?
[英]How can I change an array of documents to an array of values in MongoDB shell?
因此,基本上,我具有以下ID數組:
> arrayDeptID
[
{
"departamento_id" : 0
},
{
"departamento_id" : 2
},
{
"departamento_id" : 5
},
{
"departamento_id" : 6
}
]
我想將其轉換為僅包含文檔字段departamento_id上的值的數組,如下所示:
[0, 2, 5, 6]
在MongoDB Shell中有什么方法可以做到這一點?
使用JavaScipt .map()
:
arrayDeptID.map(function(el) { return el.departamento_id })
然后,MongoDB Shell是JavaScript REPL。 因此,幾乎所有ECMAScript內置函數都存在。 它基於V8構建,因此這里通常也包含任何內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.