By importing JSON to mongodb, I have a record that looks like following:
"_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
}
]
}
]
Question 1 - Want to update "salesRecord.monthly.sales" = 8000 with "salesRecord.monthly.sales" = 8300 for "salesRecord.monthly.brand" = "Apple" in "salesRecord.monthly.quarter" = "First".
Question 2 - Want to add new "salesRecord.monthly.month" = "May" for "salesRecord.monthly.brand" = "Apple" in "salesRecord.monthly.quarter" = "Second".
Looking for javascript snippet or preferably mongo shell commands. Answers are appreciated, thanks !