Search code examples
couchbasesql++

How do I update each element of a map with a N1QL query?


I have a document which looks like:


  "associations": {
    "MANUFACTURER": [
      "137205:24",
      "137192:24",
      "137299:24",
      "137417:24",
      "137196:24",
      "137318:24",
      "137436:24",
      "137134:24",
    ]
}

I want to iterate all the elements in MANUFACTURER and concat VBU: to all the beginning of all the elements in that list.

How would I do that?


Solution

  • Use ARRAY construct

    ARRAY "VBU:"|| v FOR v IN associations.MANUFACTURER END
    
    UPDATE mybucket AS b
    SET b.associations.MANUFACTURER = ARRAY "VBU:"|| v FOR v IN b.associations.MANUFACTURER END
    WHERE ...;