ArangoDB组和排序

ArangoDB组和排序,arangodb,aql,Arangodb,Aql,在ArangoDB中,我想对通知数据进行分组和排序 我有以下通知数据集 [ {id: 1, groupId: 1, text: 'Aoo', time: 23}, {id: 2, groupId: 2, text: 'Boo', time: 32}, {id: 3, groupId: 1, text: 'Coo', time: 45}, {id: 4, groupId: 3, text: 'Doo', time: 56}, {id: 5, groupId: 1, text:

在ArangoDB中,我想对通知数据进行分组和排序

我有以下通知数据集

[
  {id: 1, groupId: 1, text: 'Aoo', time: 23},
  {id: 2, groupId: 2, text: 'Boo', time: 32},
  {id: 3, groupId: 1, text: 'Coo', time: 45},
  {id: 4, groupId: 3, text: 'Doo', time: 56},
  {id: 5, groupId: 1, text: 'Eoo', time: 22},
  {id: 6, groupId: 2, text: 'Foo', time: 23}
]
我想按groupId对通知进行分组,最近的通知组应显示在顶部。 最终结果应该是这样的

[
  { groupId: 3, notifications: [{id: 4, groupId: 3, text: 'Doo', time: 56}],
  { groupId: 1, notification: [{id: 3, groupId: 1, text: 'Coo', time: 45}, {id: 1, groupId: 1, text: 'Aoo', time: 23}, {id: 5, groupId: 1, text: 'Eoo', time: 22}]},
  { groupId: 2, notifications: [{id: 2, groupId: 2, text: 'Boo', time: 32}, {id: 6, groupId: 2, text: 'Foo', time: 23}] }
]
尝试遵循AQL

FOR doc IN notificaion
SORT doc.time DESC
COLLECT groupId = doc.groupId INTO g
RETURN { groupId, notifications: g[*].doc }
上面的查询对内部组元素进行排序,但不对外部组进行排序

我正在努力为它建立一个AQL。任何指针都会有帮助


谢谢

对文档集进行两次排序:一次收集文档集-就像您已经做的那样,然后收集:

FOR doc IN notification
  SORT doc.time DESC
  COLLECT groupId = doc.groupId INTO g
  SORT g[*].doc.time DESC
  RETURN { groupId, notifications: g[*].doc }
在我的测试中,这会产生所需的序列:

[
  {
    "groupId": 3,
    "notifications": [
      {
        "id": 4,
        "groupId": 3,
        "text": "Doo",
        "time": 56
      }
    ]
  },
  {
    "groupId": 1,
    "notifications": [
      {
        "id": 3,
        "groupId": 1,
        "text": "Coo",
        "time": 45
      },
      {
        "id": 1,
        "groupId": 1,
        "text": "Aoo",
        "time": 23
      },
      {
        "id": 5,
        "groupId": 1,
        "text": "Eoo",
        "time": 22
      }
    ]
  },
  {
    "groupId": 2,
    "notifications": [
      {
        "id": 2,
        "groupId": 2,
        "text": "Boo",
        "time": 32
      },
      {
        "id": 6,
        "groupId": 2,
        "text": "Foo",
        "time": 23
      }
    ]
  }
]

在这个社区里会有某种互动。我的回答有用吗?我错了吗?没有你方的确认,这个问答对其他访客来说几乎毫无价值。