Update: Ignore this post. Did not see the category. As topic says Query assumed n1ql service.
CREATE INDEX ix1 ON default(clientId) WHERE type = "client";
CREATE INDEX ix2 ON default(ALL clientIds, groupId) WHERE type = "group";
SELECT c.*,
(SELECT DISTINCT RAW g.groupId
FROM default AS g
UNNEST g.clientIds AS cId
WHERE g.type = "group" AND cId = c.clientId) AS groupIds
FROM default AS c
WHERE type = "client" AND c.clientId IS NOT NULL;
The above may work for Server, but it uses features that are not available on mobile. There is not a graceful way to accomplish what you want, unfortunately. I’d recommend putting the groupID directly onto the client rather than the other way around, as it is a more horizontal way of doing things. Then you can easily select the information you want, and use joins or aggregations to get other relevant information.