Update and array value inside array by N1ql


#1

Below is my json doc;
Bucket: Default:

“channel”: “CON”,
“dtype”: “coninf”,
“con_info”: [
{
“partners”: [
{
“id”: “AIRTEL”,
“name”: “Airtel Corporation Inc”
},
{
“id”: “Snapchat”,
“name”: “Snapchat Inc”
}
],

I want to upate name inside partners array on the basis of name and dtype.
This is my query which fails to update:
UPDATE Default
SET s.id=“Test13” FOR s IN ARRAY_FLATTEN(con_info[*].partners, 1)END
WHERE dtype = ‘coninf’ and s.name=‘Airtel Corporation Inc’.

Please suggest.

Thanks
Ritu


#2
UPDATE default SET p.id = "Test13"
        FOR p IN c.partners  FOR c IN con_info WHEN p.name = "Airtel Corporation Inc" END
 WHERE dtype = "coninf" AND  
                 ANY  c1 IN con_info SATISFIES 
                          (ANY p1 IN c1.partners SATISFIES p1.name = "Airtel Corporation Inc" END) END;

Actual update value decided by FOR in the SET clause.
ANY clause in WHERE discards the documents that don’t qualify without that document qualify for update but it may not update (it is based on SET clause condition)


#3

Thanks for your help:)