user121095
user121095

Reputation: 813

For Couchbase Lite, use QueryBuilder to query on a property that is inside a nested JSON

I am new to Couchbase Lite so might be asking a really basic question. I have a requirement where I need to use the QueryBuilder to fetch the data at a property which is nested inside another property. Seems like a pretty straight forward nested query thing but I'm not able to find resources for the same. Consider the following example where I have multiple documents that follow the same document pattern:

{
  "user":{
    "id": 1,
    "metadata": {
      "anotherId": 2,
      "aRandomArray": [
        "Works",
        "WorksAsWell"
        ]
    }
  }
}

Now, how will the QueryBuilder's query look like if I have to make the query for the following use-cases:

  1. Fetch a document where id is equal to 1
  2. Fetch a document anotherId is equal to 2
  3. Fetch a document where aRandomArray contains WorksAsWell

So the question primarily revolves around how to create a query for properties that are nested inside other properties using QueryBuilder?

Upvotes: 2

Views: 193

Answers (1)

Related Questions