【发布时间】:2018-10-20 01:26:27
【问题描述】:
我有以下示例文档结构:
{
"_id" : 1,
"distributor" : "Jackson",
"systems" : [
{
"name" : "XBOX",
"quantity" : null,
},
{
"name" : "PlayStation",
"quantity" : 10,
},
{
"name" : "Nintendo",
"quantity" : 20,
},
{
"name" : "Atari",
"quantity" : null,
},
],
"games" : [
{
"name" : "Call of Duty",
"quantity" : 5
},
{
"name" : "Super Mario Bros",
"quantity" : null,
},
{
"name" : "Madden",
"quantity" : 4,
],
"comments" : null,
"contact" : "Bill"
}
我想将每个NOT NULL 嵌入文档的数量增加1。到目前为止,我能够让它更新第一个发现的非空条目(在本例中为 Playstation),但没有别的。
我想要的结果是这样的:
{
"_id" : 1,
"distributor" : "Jackson",
"systems" : [
{
"name" : "XBOX",
"quantity" : null,
},
{
"name" : "{PlayStation}",
"quantity" : 11,
},
{
"name" : "Nintendo",
"quantity" : 21,
},
{
"name" : "Atari",
"quantity" : null,
},
],
"games" : [
{
"name" : "Call of Duty",
"quantity" : 6
},
{
"name" : "Super Mario Bros",
"quantity" : null,
},
{
"name" : "Madden",
"quantity" : 5,
],
"comments" : null,
"contact" : "Bill"
}
感谢您的指导!
【问题讨论】:
-
听起来你需要聚合。到目前为止,您尝试过哪些命令?你也应该发布这些。
标签: arrays mongodb increment embedded-database documents