如何在rethinkdb中实现innerjoin的条件

how to implement conditions on innerjoin in rethinkdb

我有这个查询:

 r.db('test').table('users').getAll("amazon_11",{index:"parent"})
    .innerJoin(r.table("posts"),function (posts, user) {return posts("employeeId").eq(user("employeeId"));}).zip()
    .innerJoin(r.table("posts_facebook"),function(left,right){return left('id').eq(right('post_id'))}).zip()

我想在集合 posts_facebook 中的时间戳字段上添加条件。

我已经在时间戳字段上创建了一个索引。

这就是我的猜测:

  r.db('test').table('users').getAll("amazon_11",{index:"parent"})
    .innerJoin(r.table("posts"),function (posts, user) {return posts("employeeId").eq(user("employeeId"));}).zip()
    .innerJoin(r.table("posts_facebook"),function(left,right){return left('id').eq(right('post_id'))}).zip()
  .between(fromDate,toDate,{index:"approvedAt"})

从rethinkdb收到的错误如下:

e: Expected type TABLE_SLICE but found SEQUENCE: VALUE SEQUENCE in:
r.db("test").table("users").getAll("amazon_11", {"index": "parent"}).innerJoin(r.table("posts"), function(var_43, var_44) { return var_43("employeeId").eq(var_44("employeeId")); }).zip().innerJoin(r.table("posts_facebook"), function(var_45, var_46) { return var_45("id").eq(var_46("post_id")); }).zip().between("2016-08-01 11:31:40", "2016-08-01 11:32:00", {"index": "approvedAt"})
The date format is : YYYY-MM-DD h:i:s

如果您已经在使用 innerJoin,我会把它放在第二个 innerJoin 的正文中,例如 .innerJoin(r.table("posts_facebook"),function(left,right){return left('id').eq(right('post_id')).and(right('approvedAt').gt(fromDate)).and(right('approvedAt').lt(toDate));})。请注意,innerJoin 在大表上会非常慢,因此您可能需要考虑使用 concatMap