通过将JSON导入到mongodb,我有一条如下所示的记录:
"_id" : 1,
"salesRecord" : [
{
"quarter" : "First",
"monthly" : [
{
"brand" : "Apple",
"month" : "January",
"sales" : 8000
},
{
"brand" : "Samsung",
"month" : "January",
"sales" : 8500
}
]
},
{
"quarter" : "Second",
"monthly" : [
{
"brand" : "Apple",
"month" : "April",
"sales" : 7500
},
{
"brand" : "Samsung",
"month" : "April",
"sales" : 7200
}
]
}
]
问题1 - 想要更新“salesRecord.monthly.sales”= 8000,其中“salesRecord.monthly.sales”= 8300,“salesRecord.monthly.brand”=“Apple”in“salesRecord.monthly.quarter”=“第一”。
问题2 - 想在“salesRecord.monthly.quarter”=“Second”中为“salesRecord.monthly.brand”=“Apple”添加新的“salesRecord.monthly.month”=“May”。
寻找javascript代码段或最好是mongo shell命令。 感谢您的回答!