Here is my scenario, i have a N1QL query that query’s my Bucket for contact records and returns a list of contacts. I store phone numbers and Emails in array of objects, below is a sample of how its stored
"phones": [
{
"id": "b5684eb9-b764-4d70-b62f-d060a91d71ea",
"type": "Home",
"number": "2135551212"
},
{
"id": "ef0960b4-61db-4a85-bac9-442f38bcfe23",
"type": "Work",
"number": "3104441212"
}
],
"emails": [
{
"id": "e8964670-7c9f-4c49-9b2f-56d6b5053216",
"address": "personal@email.com",
"type": "Personal"
},
{
"id": "b32637bb-ae43-49b9-a93e-966b1a9bfdb0",
"address": "work@email.com",
"type": "Work"
}
],
This is my current query
SELECT d.id, d.first_name || " " || IFMISSINGORNULL(d.middle_name || " ", "") || d.last_name as Name,
(OBJECT v.type:v.`number` FOR v IN d.phones END).*,
(OBJECT v.otherLabel:v.`address` FOR v IN d.emails END).*
FROM Contacts as d
where _type = 'contact'
Limit 5
Offset 2
which returns me data like this
{
“Name”: “Frank Smith”,
“_id”: “ef70c38d-e902-4103-951a-b23288914e11”,
“fax”: “7145551212”,
“home”: “2135555512”,
“mobile”: “7142125555”,
“primary”: "test@home.net",
“secondary”: "test@work.com",
“work”: “3105551212”
}
what i like to get is more like this
{
“Name”: “Frank Smith”,
“_id”: “ef70c38d-e902-4103-951a-b23288914e11”,
“phones”: [
{“fax”: 9495551212},
{“home”: 2135555512},
{“mobile”: 9492125555},
{“work”: 3105551212}
],
“emails”: [
{“primary”: "test@home.net"},
{“secondary”: "test@work.com"}
]
}