我需要用和日期的列表Incidents
和他嵌套的events
排序后的DESC进行查询。默认情况下,ReQL以ASC顺序给出日期。我有以下结构:startedAt
timestamp
{ "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顺序获取嵌套事件?
这样的事情应该做到:
r.table('Incident').orderBy(r.desc('createdAt')).merge(function(row) {
return {events: row('events').orderBy(r.desc('timestamp'))};
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句