utpal poulik
utpal poulik

Reputation: 57

how-to-update-parent-document-only-in-couchbase

any one can help me about this query how can Parent-document update using couchbase N1ql query

{
    "created_at": "2020-03-26T15:50:12.318Z",

    "created_by": 1,
    "deleted_at": "",
    "frm21_submit": null,
    "id": "6cb51519-7c6b-499d-8a8d-3c85658605fc",
    "machine_category_id": [
        "7a2eb767-faca-4762-b65b-2db9e1992c82",
        "259a4bcc-feb5-4d98-88c5-b331316e19be"
    ],

    "main_parts": [

        {
            "data": {
                "deleted_at": "777",
                "frm21_submit": null,
                "manufacturing_date": "03/31/2020",
                "model": "234234234",
                "photo": null,
                "serial_number": "324324234",
                "updated_at": "2020-03-31T14:11:48.909Z"
            },
            "id": "66354d7c-4769-4f3b-914e-bb841191e323"
        }
    ]

}

i want to update parent-document only all field are dynamic i can not selected field. like

update machine set "created_by"= 1, "machine_category_id"= [
    "7a2eb767-faca-4762-b65b-2db9e1992c82",
    "259a4bcc-feb5-4d98-88c5-b331316e19be"
  ]  Where id=1

how to dynamically update parent document only with safe child or sub document nothing lose data.

{

    "created_at": "2020-03-26T15:50:12.318Z",

    "created_by": 1,

    "deleted_at": "",

    "frm21_submit": null,

    "id": "6cb51519-7c6b-499d-8a8d-3c85658605fc",

    "machine_category_id": [
        "7a2eb767-faca-4762-b65b-2db9e1992c82",
        "259a4bcc-feb5-4d98-88c5-b331316e19be"
    ]

}

Upvotes: 1

Views: 54

Answers (1)

deniswsrosa
deniswsrosa

Reputation: 2460

The problem in your update is that it is referring to an attribute called "id" which I guess that is the key of the document. To access the document id you have to call meta().id

update default set created_by= 1, machine_category_id= [
"machine",
"asdasd"
]  Where meta().id = "1"

Note that the document id is a string.

Upvotes: 0

Related Questions