Querying for the "many" for each "one" in a belongsto relationship

n1ql
query

#1

Using the definition of a belongsTo style of 1:M relationship found in this CBL article, How would one query a bucket in such a manner that each one’s many were in its results?

For example, take a bucket with only the following documents:
KV key: One
{}

KV key: Many1
{ "belongsTo": "One" }

KV key: Many2
{ "belongsTo": "One" }

KV key: Many3
{ "belongsTo": "One" }

What query could one use to get something like
[ { "ownedDocuments": ["Many1", "Many2", "Many3"]} ]
Where the row represented corresponds to One. Is this possible to do?


#2

If you are using Couchbase 4.x, you can use N1QL and the NEST operator. Please see the documentation. also see see INDEX JOINs or FLEXIBLE JOINs.