Is there a way to create a projection without explicitly listing document properties?
I have one collection for users, one for custom calendars (users: calendars have a 1: 1 relationship, but not all users own the calendar):
users: {"name":"John","role":admin [more fields]}
calendars: {"color":"blue",owner: "users/john"}
I have to return the document with
{"name":"John","role":admin,[all fields from the users collection],calendar:cal}
Is there a way to do this without listing properties from the custom document?
for cal in zcalendar
for user in zuser filter user._id == cal.owner
return ...
+3
source to share
1 answer
You can use the MERGE function for example. eg:
FOR cal IN zcalendar
FOR user IN zuser
FILTER user._id == cal.owner
LET calDoc = {
'calendar': cal
}
RETURN MERGE(user, calDoc)
What this structure returns:
[
{
"_id": "...",
"_rev": "...",
"_key": "...",
"name": "John",
"role": "admin",
"calendar": {
"_id": "...",
"_rev": "...",
"_key": "...",
"color": "blue",
"owner": "..."
}
}
]
+2
source to share