dsfsd43523 2017-01-02 18:32
浏览 46

Golang,Couchbase更新子文档并找到json路径

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog