Need to add missing entire Array in the existing document

Hi,

I have series of documents where the one important array is missing. Could you guide me how should I add them.

Existing Document

  "mybucket": {
      "aCategory": 10,
      "Id": 1234,
      "segment": 2,
       "attachments": [],
      "createDate": "2021-03-01T09:14:39.793Z",
      "creator": {
        "role": "normal",
        "roleType": 0
      },
......
}

I need to add the array to the docuemnt.

  "currentState": {
    "changedBy": {
      "role: "normal",
      "roleType": 0
    },
    "comment": "xxxx",
    "enteredDate": "2021-03-05T10:39:17.065Z",
    "stateSpecId": abc
  },

How should I add them in the document using N1QL?

Regards
Dhaval.

You mentioned array is missing, but you asking add object. If following doesn’t work. Post original document and how new document will look after update.

UPDATE mybucket AS b
SET b.currentState = [{ "changedBy": { "role: "normal", "roleType": 0 }, "comment": "xxxx", "enteredDate": "2021-03-05T10:39:17.065Z", "stateSpecId": "abc" }]
WHERE b.currentState IS MISSING;
1 Like

It has fixed the issue. Many thanks for the quick update.