INSERT INTO default VALUES("Institution::1", { "_id" : "Institution::1", "label" : "Institution 1", "unites": [ { "id": "unite-1", "label" : "unite 1" } , { "id" : "unite-2", "label" : "unite 2" }, { "id" : "unite-3", "label" : "unite 3" } ] });
INSERT INTO default VALUES("personnel::1", { "_id" : "personnel::1", "label" : "personnel 1", "unites": [ { "id" : "unite-1", "val" : "unite 1" },{ "id" : "unite-2", "val" : "unite 2" } ]});
SELECT {i.label, "unites": ARRAY {iv.id, iv.label, "personnels" :
ARRAY {p._id, p.label} FOR pv IN p.unites WHEN pv.id = iv.id END}
FOR iv IN i.unites END } AS institutions
FROM default AS i USE KEYS [ "Institution::1"] JOIN default p ON KEYS "personnel::1"
Without couchbase documents
SELECT {i.label, "unites": ARRAY {iv.id, iv.label, "personnels" :
ARRAY {p._id, p.label} FOR pv IN p.unites WHEN pv.id = iv.id END}
FOR iv IN i.unites END } AS institutions
LET i = { "_id" : "Institution::1", "label" : "Institution 1", "unites": [ { "id": "unite-1", "label" : "unite 1" } , { "id" : "unite-2", "label" : "unite 2" }, { "id" : "unite-3", "label" : "unite 3" } ] },
p = { "_id" : "personnel::1", "label" : "personnel 1", "unites": [ { "id" : "unite-1", "val" : "unite 1" },{ "id" : "unite-2", "val" : "unite 2" } ]};
At present Joins required parent-child relation ship through document key.
If the data is small you can do independent queries and materialize into array and you can JOIN.
Next release you can join through document fields.