考虑以下流(按时间戳索引):
[
{ name: "John", timestamp: 1 },
{ name: "George", timestamp: 2 }, // George's first occurrence in stream but not 'in a series'
{ name: "Ringo", timestamp: 3 },
{ name: "Paul", timestamp: 4 },
{ name: "George", timestamp: 5 }, // Bingo!
{ name: "George", timestamp: 6 },
{ name: "George", timestamp: 7 }
]
George是最后一位用户,所以这是我感兴趣的用户,他连续第一次出现(在'系列'?中)是5:{{1} }
如何使用rql获取此文档?
答案 0 :(得分:0)
目前在ReQL中做到这一点并不是一个好方法,但这就是我要做的事情:
r.table('test').filter({name: 'George'}).coerceTo('array').do(function(arr) {
return r.concatMap(arr, arr.skip(1), function(cur, next) {
return r.branch(cur('timestamp').eq(next('timestamp')), [cur], [])
})(0);
});