有没有办法在没有明确列出文档属性的情况下创建投影?

时间:2014-12-01 09:52:06

标签: arangodb aql

我有一个用户集合,一个用户日历集合(用户:日历有1:1关系,但不是所有用户都拥有日历):

users: {"name":"John","role":admin [more fields]}
calendars: {"color":"blue",owner: "users/john"}

我要返回一份文件:

{"name":"John","role":admin,[all fields from the users collection],calendar:cal}

有没有办法在不列出用户文档中的属性的情况下执行此操作?

for cal in zcalendar
    for user in zuser filter user._id == cal.owner
return ...

1 个答案:

答案 0 :(得分:2)

您可以使用MERGE文档功能,例如像这样:

FOR cal IN zcalendar
    FOR user IN zuser
        FILTER user._id == cal.owner
        LET calDoc = {
            'calendar': cal
        }
        RETURN MERGE(user, calDoc)

返回此结构:

[
  {
    "_id": "...",
    "_rev": "...",
    "_key": "...",
    "name": "John",
    "role": "admin",
    "calendar": {
      "_id": "...",
      "_rev": "...",
      "_key": "...",
      "color": "blue",
      "owner": "..."
    }
  }
]