N1Q1 UPDATE Query is not working

{

“tasks”: {
“00:00:00”: {
“endTime”: 1680220800,
“gmtOffset”: 32400,
“startTime”: 1680220800,
“time”: “00:00:00”,
“zones”: [
“Asia/Seoul”,
“Europe/Andorra”
]
},
“01:00:00”: {
“endTime”: 1680220800,
“gmtOffset”: 32400,
“startTime”: 1680220800,
“time”: “00:00:00”,
“zones”: [
“Asia/Seoul”,
“Europe/Andorra”
]
}
}
}

The following is part of my document content. Under the “tasks” field, the keys in the format “hh:mm:00” always have a gmtOffset value. I want to add 100 to the gmtOffset, but my query doesn’t work. Could you help me write a working query?

Example query:

UPDATE `your_bucket`
SET tasks = OBJECT_PUT(tasks, taskKey, OBJECT_PUT(tasks[taskKey], 'gmtOffset', tasks[taskKey].gmtOffset + 100))
FOR taskKey IN OBJECT_NAMES(tasks) END
WHERE ...;

Please try:

UPDATE `your_bucket` 
SET  tasks.[i].gmtOffset = tasks.[i].gmtOffset+100 
FOR i:_ in tasks END
WHERE ...;

If you’d like to filter the elements to be updated in the tasks object, add a WHEN clause like so:

UPDATE `your_bucket` 
SET  tasks.[i].gmtOffset = tasks.[i].gmtOffset+100 
FOR i:_ in tasks <optional WHEN clause> END
WHERE ... ;

Check out details about the WHEN clause here:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.