Dev
Dev

Reputation: 92

How can i query the access object from JSON in CouchDB

I'm using couchDB in the fabric for state database in peers. I have a json data that is stored inside the ledger

JSON DATA

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

I have to query the data based on access json object, like these have values like "create","readonly","delete" etc..

Currently I tried this but none of the records came up.

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

How can I query the data's ?

Upvotes: 0

Views: 270

Answers (1)

kekomal
kekomal

Reputation: 2200

I think you want (I use dot notation for simplicity):

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

...or maybe...

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

Upvotes: 2

Related Questions