【问题标题】:How can i query the access object from JSON in CouchDB如何从 CouchDB 中的 JSON 查询访问对象
【发布时间】:2021-08-24 10:14:01
【问题描述】:

我在结构中使用 couchDB 作为对等体中的状态数据库。我有一个存储在分类帐中的 json 数据

JSON 数据

  "Company": {
    "Associate": {
      "entity": {
        "name": "foo",
          "role": "admin"
      },
      "access": [
        {
          "create": "allowed"
        }
      ]
    }
  }
}

我必须根据 access json 对象查询数据,比如这些具有“create”、“readonly”、“delete”等值。

目前我尝试了这个,但没有任何记录出现。

{
  "selector": {
    "Company": {
      "Associate": {
        "access": {
          "$elemMatch": {
            "$eq": "create"
          }
        }
      }
    }
  }
}

如何查询数据?

【问题讨论】:

    标签: couchdb hyperledger-fabric blockchain hyperledger


    【解决方案1】:

    我想你想要(为简单起见,我使用点表示法):

    {
      "selector": {
        "Company.Associate.access": {
          "$elemMatch": {
            "create": {
              "$exists": true
            }
          }
        }
      }
    }
    

    ...或者也许...

    {
      "selector": {
        "Company.Associate.access": {
          "$elemMatch": {
            "create": "allowed"
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多