Hi,
I’m new to Couchbase and I have my document JSON schema as mentioned below;
{
"id": "C123",
"type":"Base",
"elementList":[
{
"name":"name1",
"ind":true,
"otherInd": true,
"fieldList":[
{
"key":1,
"elemSrc":"val1",
"indctr" : "N",
"reason": "reason1"
},
{
"key":2,
"elemSrc":"val2",
"indctr" : "N",
"reason": "reason2"
}
]
},
{
"name":"name2",
"ind":true,
"otherInd": true,
"fieldList":[
{
"key":1,
"elemSrc":"val1",
"indctr" : "N",
"reason": "reason1"
},
{
"key":2,
"elemSrc":"val2",
"indctr" : "N",
"reason": "reason2"
}
]
}
]
}
I need to update “elementList” on the following scenarios:
- The name field is distinct in first level array, so I need to update “ind” and “otherInd” fields for a given “name” in first level array and along with that it should update “reason” and “ind” fields in “fieldList”(second level array) for a given combination of “key” and “elemSrc” , the combination of “key” and “elemSrc” are distinct for a given “name” in the first level array.
- If name does not exist in first level array then it should create a new object and append to “elemList” array and similarly if the combination of “key” and “elemSrc” in “fieldList” is not present then the new object will be appended to the existing “fieldList” array.
I’m trying to use N1ql Update Query to achieve this, can anyone please help me on the following.
Thanks!