Update on nested Documents


#1

When having the following document structure, can I use N1QL to do an Update on a subdocument to add en extra field?

> {
> "blog": "testblog1",
> "user_id": 41,
> "comments": [
>     {
>         "comment": "testcomment1",
>         "user_id": 883
>     },
>     {
>         "comment": "testcomment2",
>         "user_id": 790
>     }
>   ]
> }

For example I would like to add the field “ranking” : “top comment” to the subdocument with the comment testcomment2:

> {
> "blog": "testblog1",
> "user_id": 41,
> "comments": [
>     {
>         "comment": "testcomment1",
>         "user_id": 883
>     },
>     {
>         "comment": "testcomment2",
>         "user_id": 790,
>         "ranking" : "top comment"
>     }
>   ]
> }

Update on deeply nested Documents
#2

@geraldss please correct me if I’m wrong but full DML capabilities and especially sub-document updates are not in scope for the first release of N1QL. This is a feature that will be made available in the following version.


#3

Hi @simonbasle, UPDATE / DELETE / INSERT will be included in the first release, including sub-document updates. It is fully implemented and tested. We may choose to label them “experimental”, but this is only to reflect to the fact that atomicity is per document, not per statement.

Thanks,
Gerald


#4

Thank you for your help. The way how the update operation is performed is described in http://stackoverflow.com/questions/29581646/couchbase-n1ql-update-on-nested-documents