I have the following N1QL that gives the below results.
SELECT
ARRAY_AGG({"product":"product::"||t2.product})[*].product
FROM (SELECT t1.id,
product,
MIN(t1.env) AS env,
MAX(status) AS status,
MIN({t1.description,
t1.dcrFlag,
t1.lastModified,
t1.name,
t1.companyId}).*
FROM (SELECT m.appName AS name,
m.uuid AS id,
m.description,
m.env,
m.companyId,
m.fourthParty AS dcrFlag,
coalesce(m.updatedTs,m.createdTs) AS lastModified,
m.productStatus ,
m.productId ,
m.status
FROM api_external AS pa
JOIN api_external AS i1
ON pa.uuid = i1.data.partnerAppId
AND i1.type = "integration"
WHERE pa.type = "partnerApp"
AND pa.data.companyId in [ "73f35ad2510a416f8e36b2e30c2230f1" ]
AND pa.deleted = false
AND i1.deleted = false
AND i1.data.env in [ "SANDBOX","PRODUCTION" ]
AND (IS_MISSING(i1.backupOf)
OR IS_NULL (i1.backupOf)
OR i1.backupOf="")
GROUP BY pa.uuid, i1.data.productStatus LETTING m = MIN([i1.data.env, {pa.uuid, pa.data.appName, pa.data.description, pa.data.fourthParty, i1.data.env, i1.data.productStatus , i1.createdTs,i1.updatedTs, i1.data.productId , i1.data.status,pa.data.companyId }])[1] ) AS t1 LEFT UNNEST OBJECT_PAIRS(t1.productStatus) AS ps LET product = IFMISSINGORNULL(t1.productId, ps.name), status = IFMISSINGORNULL(t1.status, ps.val)
GROUP BY t1.id, product) AS t2
GROUP BY t2.id
Result :
[
{
"product": [
"product::0da7ebce7ed842ad8c28df4eed766808",
"product::a68d99bbd45c490dbe006d1ce2831ca3",
"product::c1584cf57553455c8a04d8cc984c7d88"
]
},
{
"product": [
"product::a68d99bbd45c490dbe006d1ce2831ca3"
]
},
{
"product": [
"product::faf8800c727f44478ed5a4bcde6a53e3"
]
},
{
"product": [
"product::4744165edc974dafa73a8895766140cb",
"product::c1584cf57553455c8a04d8cc984c7d88"
]
},
{
"product": [
"product::0da7ebce7ed842ad8c28df4eed766808",
"product::c1584cf57553455c8a04d8cc984c7d88"
]
}
]
I want to get a single array with all the unique productIds.
Something like this
[
"product::0da7ebce7ed842ad8c28df4eed766808",
"product::a68d99bbd45c490dbe006d1ce2831ca3",
"product::c1584cf57553455c8a04d8cc984c7d88",
"product::faf8800c727f44478ed5a4bcde6a53e3
]