{startkey: ['1'], endkey: ['1',{}], include_docs: true, attachments: false, group: true}).then(function (result) {
})
4 - And the return, with one query:
// 1 - Product[ { "doc" : { "$doctype" : "product",
"_id" : "ae0ae08d2652f41e0c284a3a60042d30",
"_rev" : "1-aeb0453e5197b25a0c45df74a5b2a2c4",
"code" : "1",
"collection" : "AAA",
"description" : "PRODUCT ONE"
},
"id" : "ae0ae08d2652f41e0c284a3a60042d30",
"key" : [ "1",
0
],
"value" : null
},
// 3- relationship prodcut-color
{ "doc" : { "$doctype" : "product-color",
"_id" : "ae0ae08d2652f41e0c284a3a60049263",
"_rev" : "1-af26e51a7c53023b10489375a798cc26",
"color" : "1",
"image" : "Image1",
"product" : "1"
},
"id" : "ae0ae08d2652f41e0c284a3a60049263",
"key" : [ "1",
1
],
"value" : null
},
{ "doc" : { "$doctype" : "product-color",
"_id" : "ae0ae08d2652f41e0c284a3a60049fcf",
"_rev" : "1-df6194e9454245ca50f24250994d20f1",
"color" : "2",
"image" : "Image2",
"product" : "1"
},
"id" : "ae0ae08d2652f41e0c284a3a60049fcf",
"key" : [ "1",
1
],
"value" : null
},
{ "doc" : { "$doctype" : "product-color",
"_id" : "ae0ae08d2652f41e0c284a3a6004a280",
"_rev" : "1-b3e8fd352a3fb9e61dfbf1d62c26ce89",
"color" : "3",
"image" : "Image3",
"product" : "1"
},
"id" : "ae0ae08d2652f41e0c284a3a6004a280",
"key" : [ "1",
1
],
"value" : null
},
// 3 - colors
{ "doc" : { "$doctype" : "color",
"_id" : "1",
"_rev" : "1-5820c5257ff67676cd0e4f76595240f1",
"description" : "Blue"
},
"id" : "ae0ae08d2652f41e0c284a3a60049263",
"key" : [ "1",
2
],
"value" : { "_id" : "1" }
},
{ "doc" : { "$doctype" : "color",
"_id" : "2",
"_rev" : "1-e8b436b26fa97c4c5c3a79f618f8d9aa",
"description" : "White"
},
"id" : "ae0ae08d2652f41e0c284a3a60049fcf",
"key" : [ "1",
2
],
"value" : { "_id" : "2" }
},
{ "doc" : { "$doctype" : "color",
"_id" : "3",
"_rev" : "1-b70ff5ae1f110e73227c537ca949202d",
"description" : "Pink"
},
"id" : "ae0ae08d2652f41e0c284a3a6004a280",
"key" : [ "1",
2
],
"value" : { "_id" : "3" }
}
]
Special thanks to Nuno Job and Giovanni Parra for the help!
Fábio