I have saved a JSON Object as Mutable Document. The object looks as follows
{
“id”:“title”,
“options”:[
{
“desc”:“Mr”,
“code”:“01”,
“parent”:“M”
},
{
“desc”:“Miss”,
“code”:“02”,
“parent”:“F”
},
{
“desc”:“Mrs”,
“code”:“03”,
“parent”:“F”
}
]
}
I want to select objects where parent value is equal to ‘F’.
Is there any way to query the above document ? Or QueryBuilder only works to fetch records from collection [Couchbase Lite database] ?
See docs for examples on how you can implement the above query . Also, to level set terminology, as discussed in this post Couchbase Lite does not support collections so to avoid confusion, please refrain from referring to Couchbase Lite instance as a collection.
Look at the ANY and EVERY query expressions in the query documentation. Those let you look inside arrays.
If you’re storing a lot of stuff inside an array, however, that’s often a sign that you should break the array up into separate documents, each of which has a property that refers back to the parent document.
Thanks for response, Actually the example covered here is querying from database and will result all documents that matches the expression. In my case i want to search from a document i have fetched the document by its id and type now that document contains an array “options” and i want to query on that options array.
The reason i am searching from specific document is that the value can possibly exists in multiple documents. Lets say Gender=F this value can be a part of multiple documents of same type and of different type as well i.e (Customer,Account detail,Martial Status) etc, if i search from database using the above query it will return all documents. My purpose its to get title whose parent value is equal to ‘F’.
Tried to use ANY and EVERY query expressions as suggested by @jens but couldn’t find it in DOCS.
Those docs are pretty high-level and don’t cover every single query operation. Check the full Java API docs. (I don’t know the Java API, I work at a lower level on the core engine, so I can’t tell you exactly what the API is.)
Used QueryBuilder to fetch an array of specific document based on some condition but was unable to find the complete JSON Object from an array as per the answer here it will not be supported to do so using Query.
Below is the Query i used to find options array from a specific document where Gender=‘F’.
Okay Got your point.
Yes i am just testing to retrieve multiple documents and single document as well as in some cases we have document id and we need to get data from that document so that is why query looks like this.