Collection based query in CBL 2.0


We have a similar doc structure for one of the type of document:-

“CollectionSamples”: [
“DocNumber”: “XYZ101FOODOC”,
“DocType”: “P”
“DocNumber”: “XYZ101FOODOC”,
“DocType”: “X”
“ExpiryDateEpoch”: 1800921600,
“lastModifiedBy”: “SYSTEM”,
“lastModifiedDate”: “2017-11-09 21:26:24.2978531 +05:30”,
“PersonID”: “0002218D-C485-4C7B-8A6C-F7D10F880568”,
“type”: “DocumentTypeA”

Where we need to write a query in which for inside the CollectionSamples if any collection got DocType=P and DocNumber=@variable then select PersonID.
Using N1QL or 1.4.1 its easy to emit the DocNumber,PersonID when the DocType==P but I am not able to find an example how to do this in 2.0

Please help me shorting this out so that we can look into the chances of migration.


@househippo, @jens Can you help on this ?


Have you looked at the examples in this blog ? Check out the section on handling nested arrays.