Golang , Couchbase updating sub document and finding json path

298 views Asked by At

What is the best approach to update sub document in couchbase ? I am taking about nested json documents . Simple fields are easily updatable using syntax like set name = 'Jon Doe' but what about nested json document . I have read all the pages in the official document but all the pages used a phase called keys or path which is a json path.

So for a complex nested json like org.adddress.city.name how to find the path dynamically or programmatically from json . Think a nested json with 6-7 level deep . Its hardly be seen but what about it .

Sub document updating in couchbase means updating a portion or part of the entire document or updating a simple field that could be nested .

My way is to find a Merge Json Patch that will give me which json field is updated and then if that patch contains nested fields like "address": { "city": { "id": "25", "name": "Atlanta" } } then to update this in Couchbase using mutate_in function I need those path which is address.city.id and address.city.name . Even if in N1QL query to update the doc I need to generate those path I believe .

I have been trying to generate those path from json using recursion function because you don’t know how far the next will be . Here is the gist .

I would like to know If there are any other way without generating the path to update complex sub documents.

0

There are 0 answers