Update main document and nested document based on its objectid

Hi everyone,

I am having a json as,
{
“_id” : 1,
“item” : “TBD”,
“stock” : 0,
“info” : { “publisher” : “1111”, “pages” : 430 },
“tags” : [ “technology”, “computer” ],
“ratings” : [ { “by” : “ijk”, “rating” : 4 ,“_id”:“2”}, { “by” : “lmn”, “rating” : 5 ,“id”= “3”} ],
“publicratings” : [ { “by” : “ijk1”, “rating” : 4 ,“_id”:“4”}, { “by” : “lmn1”, “rating” : 5 ,“id”= “5”} ],
“reorder” : false
}

I want to add new field “status” to parent and “Active” to child object based on id

{
“_id” : 1,
“item” : “TBD”,
“stock” : 0,
“info” : { “publisher” : “1111”, “pages” : 430 },
“tags” : [ “technology”, “computer” ],
“ratings” : [ { “by” : “ijk”, “rating” : 4 ,“_id”:“2”,“Active”:0}, { “by” : “lmn”, “rating” : 5 ,“id”= “3”,Active=“0”
} ],
“publicratings” : [ { “by” : “ijk1”, “rating” : 4 ,“_id”:“4”,“Active”:0}, { “by” : “lmn1”, “rating” : 5 ,“id”= “5”,“Active”:0} ],
“reorder” : false,
“STATUS”: “A”
}

Please help in query to update as above

Please read Formatting code and log snippets in posts and update your documents so that we can cut-n-paste into our systems.

1 Like