我需要在Incidents
和events
日期之前使用startedAt
列表及其嵌套的timestamp
有序DESC进行查询。默认情况下,ReQL为日期提供ASC订单。我有以下结构:
{
"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'))
,事件按{G} createdAt
排序。但嵌套的events
仍然是ASC命令。
如何通过按时间戳获取带有DESC顺序的嵌套事件来进行查询?
答案 0 :(得分:2)
这样的事情应该这样做:
r.table('Incident').orderBy(r.desc('createdAt')).merge(function(row) {
return {events: row('events').orderBy(r.desc('timestamp'))};
})
答案 1 :(得分: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"))
}
})