Lets say we have some documents of type “file” like this:
{
"_id": "file::001",
"type": "file",
"name": "this is a file",
"tags": [
{
"tagId": "tag::001",
"addedAt": "32095823",
},
{
"tagId": "tag::002",
"addedAt": "32482931",
}
]
}, ...
and want to join them with the following documents of type “tag”:
{
"_id": "tag::001",
"type": "tag",
"color": "green",
"name": "this is a green tag"
},
{
"_id": "tag::002",
"type": "tag",
"color": "blue",
"name": "this is a blue tag"
}
to this expected result:
{
"_id": "file::001",
"type": "file",
"name": "File 1",
"tags": [
{
"tagId": "tag::001",
"addedAt": "32095823",
// tags will be joined into this nested property
"tag": {
"type": "tag",
"color": "green",
"name": "this is a green tag"
}
},
{
"tagId": "tag::002",
"addedAt": "32482931",
"tag": {
"type": "tag",
"color": "blue",
"name": "this is a blue tag"
}
}
]
}
I’ve been searching the whole day yesterday and couldn’t find any solution to this problem (which seems very basic and common to me). Maybe i’ve been using the wrong keywords, as i’m very new to n1ql. Keep in mind, that i am searching for a Couchbase Lite / Mobile solution.
If anyone could help me write a query or at least nudge me into the right direction with some documentation links, i’d be very thankfull.