How to update couchbase inner-structured records?

Intro

Hi everyone, Although I read the Couchbase documentation, it was unclear to me. I want to update specific field’s values in Couchbase. I can’t figure out how to do this because the structure is a little it complex.

The Structure

"shops": {
    "1": {
      "workingHours": [
        {
          "interval": {
            "closed": 15,
            "open": 9
          },
          "info": {
            "name": xBurger,
            "location": London
          }
        },
        {
          "interval": {
            "closed": 18,
            "open": 8
          },
          "info": {
            "name": Pizzeria,
            "location": Venice
          }
        },
       ]

NEEDS

I need to change the open-closed hours. If open-closed hour is 9-15 → change it to 12-20 If open-closed hour is 8-18 → change it to 10-16

Try

update shops set v.interval = {
    "open": case when v.interval.open = 9 and v.interval.closed = 15 then 12
                 when v.interval.open = 8 and v.interval.closed = 18 then 10
            end,
    "closed": case when v.interval.open = 9 and v.interval.closed = 15 then 20
                   when v.interval.open = 8 and v.interval.closed = 18 then 16
              end
    }
  for v in `1`.workingHours when (v.interval.open = 9 and v.interval.closed = 15) or (v.interval.open = 8 and v.interval.closed = 18) end;

This will update all shops


INSERT INTO default VALUES("f001", { "shops": { "1": { "workingHours": [ { "interval": { "closed": 15, "open": 9 }, "info": { "name": "Burger", "location": "London" } }, { "interval": { "closed": 18, "open": 8 }, "info": { "name": "Pizzeria", "location": "Venice" } } ] }, "2": { "workingHours": [ { "interval": { "closed": 15, "open": 9 }, "info": { "name": "Burger", "location": "London" } }, { "interval": { "closed": 18, "open": 10 }, "info": { "name": "Pizzeria", "location": "Venice" } } ] } } });

UPDATE default AS d
SET wh.interval = OBJECT_CONCAT(wh.interval, {"open":12, "closed":20})
         FOR wh IN nv.workingHours
               FOR ns:nv IN d.shops
             WHEN wh.interval.open = 9 AND wh.interval.closed = 15 END,
   wh.interval = OBJECT_CONCAT(wh.interval, {"open":10, "closed":16})
         FOR wh IN nv.workingHours
               FOR ns:nv IN d.shops
             WHEN wh.interval.open = 8 AND wh.interval.closed = 18 END;