0

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.

Community
  • 1
  • 1
sh0umik
  • 1,549
  • 2
  • 17
  • 27
  • I'm sorry, your question is not clear. If you need to generate the paths dynamically, you can generate a N1QL query dynamically. – geraldss Jan 03 '17 at 17:03
  • I can but even N1Ql requires a path to update the sub document `SET path = expression [update-for] [ , path = expression [update-for] ]*` so my question is how to generate path for complex nested json like above – sh0umik Jan 03 '17 at 17:35
  • Generate the path in your code, then generate your N1QL query dynamically, on the fly, from your code. It's just a string. – geraldss Jan 03 '17 at 17:55

0 Answers0