Reputation: 79
{
"name":"nick",
"emailId":"[email protected]",
"subjects" : [{
"name":"SOA",
"tutor":"roshan",
"classes" : "12"
},
{
"name":"UNIX",
"tutor":"mathew",
"classes" : "9"
}
],
"id" : "12345"
}
I want to add another set of subjects using update query.
i tired to put some query by seeing some website but it show error and i am unable to understand.
It will be more helpful if you give suggestion and thanks for the help.
the query which i tired was :-
[update studapp
ARRAY a.name= "networks", a.tutor= "shalin" ,a.classes= "8"
FOR a IN subjects END
where id = '12345';]
Upvotes: 1
Views: 3649
Reputation: 79
update `studapp`
SET subjects= ARRAY_APPEND( subjects, { "name":"SE",
"tutor":"Mani",
"classes" : "7" } )
where id = '12345';
I got result as i needed (adding set of new values to the existing array)
RESULT
{
"name":"nick",
"emailId":"[email protected]",
"subjects" : [{
"name":"SOA",
"tutor":"roshan",
"classes" : "12"
},
{
"name":"UNIX",
"tutor":"mathew",
"classes" : "9"
}
{
"name":"SE",
"tutor":"Mani",
"classes" : "7"
}
],
"id" : "12345"
}
Upvotes: 5
Reputation: 2445
See
n1ql query to remove data from array which has parameter value null
https://dzone.com/articles/couchbase-n1ql-continuing-to-simplify-transition-f
https://forums.couchbase.com/t/update-value-in-an-array-of-strings-within-an-array/9797
n1ql query to update multiple parameters in array of json data
Update specific object in the array of object in couchbase 4.1
Upvotes: 0