Click here to Skip to main content
15,889,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
{
  "General": {
    "Setting": [
      {
        "Name": {
          "MetaData": {
            "type": "bool"
          }
        }
      },
      {
        "Name": {
          "MetaData": {
            "type": "bool"
          }
        }
      },
      {
        "Name": {
          "MetaData": {
            "type": "bool"
          }
        }
      }
    ]
  }
}

i have the above document i need to update General.Setting.[index].Name.MetaData.type to General.Setting.[index].Name.MetaData.Newtype


What I have tried:

i did tried using this query :
1st approach:
doc.forEach( function(d) {
var settingsCollectionJSON = d.General.Setting;
settingsCollectionJSON.forEach( function(temp) {
var settingsCollectionJSONobj = temp.Name.MetaData.Localizable;
db.getCollection('SettingCollection').update(temp, { $rename: { "Name.MetaData.type": "Name.MetaData.Newtype" } })
})

})

2nd approach using $set and $unset.
//db.getCollection('SettingCollection').update(temp, { $set:{'MetaData.0.type':settingsCollectionJSONobj}, $unset: {'MetaData.0.Newtype':1} })

but for both these i'm not getting updated.can i have any solution?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900