Mysql 日期间过滤器的等效数据库

Mysql 日期间过滤器的等效数据库,mysql,rethinkdb,Mysql,Rethinkdb,我对来自MySQL的RejectDB非常陌生,我有一些任务使用RejectDB 现在,我想实现一些类似于 MySQL: select * from reservations where room_id = '7cc8e51d-e3fa-4d84-b7e6-9ebf8975754a' and ((reservation_start between `11-01-2018 00:00:00` and `11-30-2018 23:59:59`) OR (reservati

我对来自MySQL的RejectDB非常陌生,我有一些任务使用RejectDB

现在,我想实现一些类似于

MySQL:

select * 
from reservations
where 
    room_id = '7cc8e51d-e3fa-4d84-b7e6-9ebf8975754a' and
    ((reservation_start between `11-01-2018 00:00:00` and `11-30-2018 23:59:59`) OR
    (reservation_end between `11-01-2018 00:00:00` and `11-30-2018 23:59:59`))
db:

select * 
from reservations
where 
    room_id = '7cc8e51d-e3fa-4d84-b7e6-9ebf8975754a' and
    ((reservation_start between `11-01-2018 00:00:00` and `11-30-2018 23:59:59`) OR
    (reservation_end between `11-01-2018 00:00:00` and `11-30-2018 23:59:59`))
由于@Peter:

r.db("myDb").table("reservations").filter(function(doc){ 
    return 
        doc("room_id").eq("7cc8e51d-e3fa-4d84-b7e6-9ebf8975754a")
            .and(doc("reservation_start").gt("2018-12-01T00:00:00").and(doc("reservation_start").lt("2018-12-10T23:59:59"))
                .or(doc("reservation_end").gt("2018-12-01T00:00:00").and(doc("reservation_end").lt("2018-12-10T23:59:59"))))
    }
)
但我不知道如何将两个日期范围检查转换为多个日期范围检查


谢谢

根据存储日期的格式:

备选案文1:

r.db("myDB").table("reservations").filter(function (doc) {
    return doc("reservation_date").during(
        r.time(2018, 11, 10, 'Z'), r.time(2018, 11, 20, 'Z'));
})
备选案文2:

 r.db("myDB").table("reservations").filter(function(doc){ 
  return doc("reservation_date").gt("2018-11-10T18:15:31.000000Z")
    .and(doc("reservation_date").lt("2018-11-20T18:15:31.000000Z"))})
提高性能的替代方法:

在预订日期创建索引:

  r.db("myDB").table("reservations").indexCreate("reservation_date")
然后使用以下查询:

  r.db("myDB").table('reservations')
    .between("2018-11-10T18:15:31.000000Z",
             "2018-11-20T18:15:31.000000Z", {index: "reservation_date"})

现在我更了解你的问题了

首先要将查询转换为java:

r.db("myDb").table("reservations").filter(doc ->
    doc.g("room_id").eq("7cc8e51d-e3fa-4d84-b7e6-9ebf8975754a")
      .and(doc.g("reservation_start").gt("2018-12-01T00:00:00").and(doc.g("reservation_start").lt("2018-12-10T23:59:59"))
      .or(doc.g("reservation_end").gt("2018-12-01T00:00:00").and(doc.g("reservation_end").lt("2018-12-10T23:59:59")))))
现在,您最好使用房间id作为辅助索引:

r、 db(“myDB”).表格(“预订”).索引(“房间id”)

然后,您可以在查询中使用:

 r.db("myDb").table("reservations")
    .getAll("7cc8e51d-e3fa-4d84-b7e6-9ebf8975754a")
    .optArg("index","room_id")
    .filter(...)
“但我不知道如何将这两个日期范围的检查转换为 多个之间。”

1.)创建复合数组索引

r.db("myDb").table("reservations").indexCreate(
    "reservation_date", [r.row("reservation_start"), r.row("reservation_end")]
2.)使用中间查询

r.db("myDb").table("reservations").between(
    ["2018-12-01T00:00:00", "2018-12-01T00:00:00"], ["2018-12-10T23:59:59", "2018-12-10T23:59:59"], {index: "reservation_date"}
)    

//注意:现在,当您还需要房间id时,这会变得很棘手:)

谢谢@Peter,我更新了查询,现在它使用了两个日期范围检查。我试着使用
between()
,它可以工作。。。但是关于要求。。。它需要两张支票
start
end
。顺便说一句,我正在回避那些使用
function(doc){}
的人,因为我不知道如何将其转换为java表达式。谢谢@Peter,我现在使用filter()使其工作,您的答案是:)