【发布时间】:2015-06-26 11:11:45
【问题描述】:
拥有以下名为 eshops 的集合:
{
"_id" : ObjectId("53e87e239ae974e6a0a81004"),
"name" : "www.example.com",
"products" : [
{
"name" : "apple", //lets say the name key here is primary key of products
"status" : 0
},
{
"name" : "banana",
"status" : 0
},
{
"name" : "iphone",
"status" : 0
}
]
}
拥有这个数组
var products = [
{name: "apple", status: 1}
{name: "notebook", status: 0}
]
如果我想要以下结果,更新查询应该是什么样子?
{
"_id" : ObjectId("53e87e239ae974e6a0a81004"),
"name" : "www.example.com",
"products" : [
{
"name" : "apple",
"status" : 1
},
{
"name" : "banana",
"status" : 0
},
{
"name" : "iphone",
"status" : 0
},
{
"name" : "notebook",
"status" : 0
}
]
}
【问题讨论】:
标签: javascript arrays mongodb mongodb-query