1

我需要用他的和日期的列表Incidents和他的嵌套events有序 DESC进行查询。默认情况下,ReQL 以 ASC 顺序给出日期。我有以下结构: startedAttimestamp { "id": "87e14db8-1e15-4718-baac-f1c785e985cb" , "title": "Connection Error" "startedAt": Mon Oct 26 2015 14:33:00 GMT+00:00 , "events": [{ "message": "Cannot connect to theserver.com", "timestamp": Mon Oct 26 2015 14:33:00 GMT+00:00 },{ "message": "Cannot connect to theserver.com," "timestamp": Mon Oct 26 2015 14:33:20 GMT+00:00 },{ "message": "Cannot connect to theserver.com", "timestamp": Mon Oct 26 2015 14:33:40 GMT+00:00 }] },{ "id": "87e14db8-1e15-4718-baac-f1c785e985cb" , "title": "Other Connection Error" "startedAt": Mon Oct 26 2015 14:34:20 GMT+00:00 , "events": [{ "message": "Connection rejected", "timestamp": Mon Oct 26 2015 14:34:20 GMT+00:00 },{ "message": "Connection rejected", "timestamp": Mon Oct 26 2015 14:34:41 GMT+00:00 }] },{ ... (several more) }

如果我运行r.db('mydb').table('Incident').orderBy(r.desc('createdAt')),则事件createdAt将按预期排序。但是嵌套events的仍然是有序的 ASC。

如何进行查询以按时间戳获取具有 DESC 顺序的嵌套事件?

4

2 回答 2

2

这样的事情应该这样做:

r.table('Incident').orderBy(r.desc('createdAt')).merge(function(row) {
  return {events: row('events').orderBy(r.desc('timestamp'))};
})
于 2015-10-26T18:48:54.607 回答
2

我想这就是你要找的。只是对这个方法有点神奇.map(...)

r.db("test").table("stackoverflow").orderBy(r.desc('startedAt')).map(function(d){
  return {
    "startedAt":d("startedAt"),
    "title": d("title"),
    "id": d("id"),
    "events": d("events").orderBy(r.desc("timestamp"))
  }
})
于 2015-10-26T19:07:16.083 回答