如果这是一个非常基本的/noob问题,我很抱歉,但是我对来自sql的db还很陌生。
(1)
下面是我想转换成DB的sql查询。这可能真的很简单,但我不能使它正确。
sql等效项:
select *
from reservations
where
room_id = 'b1a7ddd3-ddfd-4624-8e85-79b47fb19f99' and
now() between reservation_start and reservation_end
数据库查询(有错误):
r.db("myDb").table("reservations").filter(function(doc){
return
doc("room_id").eq("b1a7ddd3-ddfd-4624-8e85-79b47fb19f99")
.and( r.now().between(doc("reservation_start ").date(), doc("reservation_end").date()) )
}
)
我只想返回预定今天,或正在进行,如果它已经开始,但尚未完成(结束日期时间)。
(2)
预订为与会者提供了一个列或字段,即姓名/电子邮件的列表/数组:
attendees: [
{"name": "Attendee 1", "email": "attendee1@test.com"},
{"name": "Attendee 2", "email": "attendee2@test.com"},
{"name": "Attendee 3", "email": "attendee3@test.com"},
]
我想添加一个过滤器来检查 email
存在于 list of attendees
.
这就像查询:电子邮件 attendee2@test.com
今天预订了 room 101
.
如果使用attende电子邮件进行查询是不可能或复杂的。。。我不介意,因为我可以在我的申请表上做检查。重要的是数据库的查询等价于 now() between dateColumnStart and dateColumnEnd
.
更新:添加了存储在db(db)中的示例数据
{
"attendees": [
{
"email": dummyUser101@gmail.com, »
"name": "Dummy User 101"
} ,
{
"email": dummyUser102@gmail.com, »
"name": "Dummy User 102"
}
] ,
"id": "45qum29cel0cm4ejl2obi6pttj" ,
"room_id": "7cc8e51d-e3fa-4d84-b7e6-9ebf8975754a" ,
"reservation_end": "2018-11-23T02:00:00" , //10AM (GMT8)
"reservation_start": "2018-11-19T00:00:00" , //8AM (GMT8)
"details": "Week event 8AM-10AM Test"
}
{
"attendees": [
{
"email": dummyUser103@gmail.com, »
"name": "Dummy User 103"
} ,
{
"email": dummyUser101@gmail.com, »
"name": "Dummy User 101"
} ,
{
"email": dummyUser102@gmail.com, »
"name": "Dummy User 102"
}
] ,
"id": "6ejq8h6tvlpnjiskvt4kthfmss_20181123T060000Z" ,
"room_id": "7cc8e51d-e3fa-4d84-b7e6-9ebf8975754a" ,
"reservation_end": "2018-11-23T07:00:00" , //3PM (GMT8)
"reservation_start": "2018-11-23T06:00:00" , //2PM (GMT8)
"details": "Test Reservation"
}
谢谢!
1条答案
按热度按时间sg2wtvxw1#
(1)
不能在筛选器中使用between。在两个键之间获取所有文档。请参阅以下文档:https://www.rethinkdb.com/api/javascript/between/
你需要的是“在”关键字。