Hi,
Below is my Document with “allDocs” as Document key inside “info” bucket
{
“userList”: [
{
“icon”: “NA”,
“description”: “NA”,
“name”: “ABC”,
“status”: “0”
},
{
“icon”: “NA”,
“description”: “NA”,
“name”: “XYZ”,
“status”: “0”
}
]
}
I want to compare the name inside the Array Object
if not present then Add the Object in to Array
If Presnt then Update the Object.
I am able to just Update the array with object using below query
UPDATE info
USE KEYS ‘allDocs’ SET userList= ARRAY_APPEND( userList, {
“icon”: “NA”,
“description”: “NA”,
“name”: “123”,
“status”: “0”
} ) ;
But, first i want to check if the any of the array object contains “name” : 123, if present then update the Object else add it as New Object in to Array.
I tried multiple queries one of which is
UPDATE info
USE KEYS ‘allDocs’ SET userList= ARRAY_DISTINCT( ARRAY_APPEND( ARRAY CASE WHEN x.name= ‘123’ THEN {
“icon”: “NA”,
“description”: “NA”,
“name”: “123”,
“status”: “0”
} ELSE x END, {
“icon”: “NA”,
“description”: “NA”,
“name”: “123”,
“status”: “0”
} ) END);
it gave syntax Errors.
can you please help me in this.