I have the following structure for my document:
{
"Name": "Test",
"FieldsCollection": [{
"GroupName": "Group",
"Fields": [{
"FieldName": "ABC",
"Fields": {
"item1": "value1",
"item2": "value2"
}
}]
}]
}
and I need to change it to be as follows:
{
"Name": "Test",
"FieldsCollection": [{
"GroupName": "Group",
"Fields": [{
"FieldName": "ABC",
"item1": "value1",
"item2": "value2"
}]
}]
}
Assuming that the values for "item1": "value1","item2": "value2" are constant for all the documents in my collection, I thought I could just remove "FieldsCollection.Fields.Fields" and add "item1": "value1","item2": "value2"
I tried the following query:
db.getCollection('Devices').update(
{"FieldsCollection.Fields.FieldName":"ABC"},
{$unset: {"FieldsCollection.Fields.Fields":1}},
{multi:true}
)
But it didn't work.
What query can I use to perform this change?