如何在rethinkdb中实现innerjoin的条件



我有这个查询:

 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: 应为TABLE_SLICE类型,但找到SEQUENCE:值序列:
r.db("test").table("users").getAll("amazon_11",{"index":"parent"}11:31:40","2016-08-01 11:32:00",{"index":"approvedAt"})
日期格式为: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

最新更新