RethinkDb query current date time between two date columns
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Sorry if this a really a basic/noob question, but I am really new to rethinkDb coming from SQL.
(1)
Below is the query in SQL that I wanted to convert into ReThinkDb. This may be really simple, but I cannot make it right.
SQL equivalent:
select *
from reservations
where
room_id = 'b1a7ddd3-ddfd-4624-8e85-79b47fb19f99' and
now() between reservation_start and reservation_end
RethinkDb Query (with error):
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()) )
}
)
I just want to return the reservations scheduled today, or ongoing if it is already started but not yet finished (end date-time).
(2)
Reservations have a column or field for attendees which is a list/array of name/email:
attendees: [
{"name": "Attendee 1", "email": "attendee1@test.com"},
{"name": "Attendee 2", "email": "attendee2@test.com"},
{"name": "Attendee 3", "email": "attendee3@test.com"},
]
I would like to add a filter to check that an email
exists in the list of attendees
.
It is like querying for: The email attendee2@test.com
has a reservation today for room 101
.
If querying with attende email is not possible or complicated... I don't mind as I can do the checking in my application. What matters is the rethinkdb query equivalent for now() between dateColumnStart and dateColumnEnd
.
Update: Added sample data stored in DB (RethinkDB)
{
"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"
}
Thanks!
mysql sql rethinkdb
add a comment |
Sorry if this a really a basic/noob question, but I am really new to rethinkDb coming from SQL.
(1)
Below is the query in SQL that I wanted to convert into ReThinkDb. This may be really simple, but I cannot make it right.
SQL equivalent:
select *
from reservations
where
room_id = 'b1a7ddd3-ddfd-4624-8e85-79b47fb19f99' and
now() between reservation_start and reservation_end
RethinkDb Query (with error):
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()) )
}
)
I just want to return the reservations scheduled today, or ongoing if it is already started but not yet finished (end date-time).
(2)
Reservations have a column or field for attendees which is a list/array of name/email:
attendees: [
{"name": "Attendee 1", "email": "attendee1@test.com"},
{"name": "Attendee 2", "email": "attendee2@test.com"},
{"name": "Attendee 3", "email": "attendee3@test.com"},
]
I would like to add a filter to check that an email
exists in the list of attendees
.
It is like querying for: The email attendee2@test.com
has a reservation today for room 101
.
If querying with attende email is not possible or complicated... I don't mind as I can do the checking in my application. What matters is the rethinkdb query equivalent for now() between dateColumnStart and dateColumnEnd
.
Update: Added sample data stored in DB (RethinkDB)
{
"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"
}
Thanks!
mysql sql rethinkdb
add a comment |
Sorry if this a really a basic/noob question, but I am really new to rethinkDb coming from SQL.
(1)
Below is the query in SQL that I wanted to convert into ReThinkDb. This may be really simple, but I cannot make it right.
SQL equivalent:
select *
from reservations
where
room_id = 'b1a7ddd3-ddfd-4624-8e85-79b47fb19f99' and
now() between reservation_start and reservation_end
RethinkDb Query (with error):
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()) )
}
)
I just want to return the reservations scheduled today, or ongoing if it is already started but not yet finished (end date-time).
(2)
Reservations have a column or field for attendees which is a list/array of name/email:
attendees: [
{"name": "Attendee 1", "email": "attendee1@test.com"},
{"name": "Attendee 2", "email": "attendee2@test.com"},
{"name": "Attendee 3", "email": "attendee3@test.com"},
]
I would like to add a filter to check that an email
exists in the list of attendees
.
It is like querying for: The email attendee2@test.com
has a reservation today for room 101
.
If querying with attende email is not possible or complicated... I don't mind as I can do the checking in my application. What matters is the rethinkdb query equivalent for now() between dateColumnStart and dateColumnEnd
.
Update: Added sample data stored in DB (RethinkDB)
{
"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"
}
Thanks!
mysql sql rethinkdb
Sorry if this a really a basic/noob question, but I am really new to rethinkDb coming from SQL.
(1)
Below is the query in SQL that I wanted to convert into ReThinkDb. This may be really simple, but I cannot make it right.
SQL equivalent:
select *
from reservations
where
room_id = 'b1a7ddd3-ddfd-4624-8e85-79b47fb19f99' and
now() between reservation_start and reservation_end
RethinkDb Query (with error):
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()) )
}
)
I just want to return the reservations scheduled today, or ongoing if it is already started but not yet finished (end date-time).
(2)
Reservations have a column or field for attendees which is a list/array of name/email:
attendees: [
{"name": "Attendee 1", "email": "attendee1@test.com"},
{"name": "Attendee 2", "email": "attendee2@test.com"},
{"name": "Attendee 3", "email": "attendee3@test.com"},
]
I would like to add a filter to check that an email
exists in the list of attendees
.
It is like querying for: The email attendee2@test.com
has a reservation today for room 101
.
If querying with attende email is not possible or complicated... I don't mind as I can do the checking in my application. What matters is the rethinkdb query equivalent for now() between dateColumnStart and dateColumnEnd
.
Update: Added sample data stored in DB (RethinkDB)
{
"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"
}
Thanks!
mysql sql rethinkdb
mysql sql rethinkdb
edited Nov 17 '18 at 3:30
Borgy Manotoy
asked Nov 16 '18 at 15:16
Borgy ManotoyBorgy Manotoy
1,0901224
1,0901224
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
(1)
You cannot use between in the filter. Between gets you all documents between two keys. See docu here: https://www.rethinkdb.com/api/javascript/between/
What you need is the "during" keyword.
r.db("myDB").table("reservations").filter(function(doc){
return doc("room_id").eq("b1a7ddd3-ddfd-4624-8e85-79b47fb19f99")
.and( r.now().during(
r.ISO8601(doc("reservation_start"),{defaultTimezone:"+08:00"}),
r.ISO8601(doc("reservation_end"),{defaultTimezone:"+08:00"})))
}
)
I tried, but I am getting errore: ISO 8601 string has no time zone, and no default time zone was provided
– Borgy Manotoy
Nov 16 '18 at 16:13
Can you send an example how your dates are stored?
– taygetos
Nov 16 '18 at 16:32
ex: "2018-11-12T08:30:00"
– Borgy Manotoy
Nov 16 '18 at 16:45
then you have to provide a defaultTimezone argument. eg.: "Z" for UTC. See my edit
– taygetos
Nov 16 '18 at 16:54
Hi @Peter, I tried and it did not return any error... but I did not get any result either. I updated the post and added a sample data from DB. I am thinking the problem is on the date format. I feel so dumb with rethinkDb :( it would be really fast to work this out if the project is in SQL.
– Borgy Manotoy
Nov 17 '18 at 3:32
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53340607%2frethinkdb-query-current-date-time-between-two-date-columns%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
(1)
You cannot use between in the filter. Between gets you all documents between two keys. See docu here: https://www.rethinkdb.com/api/javascript/between/
What you need is the "during" keyword.
r.db("myDB").table("reservations").filter(function(doc){
return doc("room_id").eq("b1a7ddd3-ddfd-4624-8e85-79b47fb19f99")
.and( r.now().during(
r.ISO8601(doc("reservation_start"),{defaultTimezone:"+08:00"}),
r.ISO8601(doc("reservation_end"),{defaultTimezone:"+08:00"})))
}
)
I tried, but I am getting errore: ISO 8601 string has no time zone, and no default time zone was provided
– Borgy Manotoy
Nov 16 '18 at 16:13
Can you send an example how your dates are stored?
– taygetos
Nov 16 '18 at 16:32
ex: "2018-11-12T08:30:00"
– Borgy Manotoy
Nov 16 '18 at 16:45
then you have to provide a defaultTimezone argument. eg.: "Z" for UTC. See my edit
– taygetos
Nov 16 '18 at 16:54
Hi @Peter, I tried and it did not return any error... but I did not get any result either. I updated the post and added a sample data from DB. I am thinking the problem is on the date format. I feel so dumb with rethinkDb :( it would be really fast to work this out if the project is in SQL.
– Borgy Manotoy
Nov 17 '18 at 3:32
|
show 3 more comments
(1)
You cannot use between in the filter. Between gets you all documents between two keys. See docu here: https://www.rethinkdb.com/api/javascript/between/
What you need is the "during" keyword.
r.db("myDB").table("reservations").filter(function(doc){
return doc("room_id").eq("b1a7ddd3-ddfd-4624-8e85-79b47fb19f99")
.and( r.now().during(
r.ISO8601(doc("reservation_start"),{defaultTimezone:"+08:00"}),
r.ISO8601(doc("reservation_end"),{defaultTimezone:"+08:00"})))
}
)
I tried, but I am getting errore: ISO 8601 string has no time zone, and no default time zone was provided
– Borgy Manotoy
Nov 16 '18 at 16:13
Can you send an example how your dates are stored?
– taygetos
Nov 16 '18 at 16:32
ex: "2018-11-12T08:30:00"
– Borgy Manotoy
Nov 16 '18 at 16:45
then you have to provide a defaultTimezone argument. eg.: "Z" for UTC. See my edit
– taygetos
Nov 16 '18 at 16:54
Hi @Peter, I tried and it did not return any error... but I did not get any result either. I updated the post and added a sample data from DB. I am thinking the problem is on the date format. I feel so dumb with rethinkDb :( it would be really fast to work this out if the project is in SQL.
– Borgy Manotoy
Nov 17 '18 at 3:32
|
show 3 more comments
(1)
You cannot use between in the filter. Between gets you all documents between two keys. See docu here: https://www.rethinkdb.com/api/javascript/between/
What you need is the "during" keyword.
r.db("myDB").table("reservations").filter(function(doc){
return doc("room_id").eq("b1a7ddd3-ddfd-4624-8e85-79b47fb19f99")
.and( r.now().during(
r.ISO8601(doc("reservation_start"),{defaultTimezone:"+08:00"}),
r.ISO8601(doc("reservation_end"),{defaultTimezone:"+08:00"})))
}
)
(1)
You cannot use between in the filter. Between gets you all documents between two keys. See docu here: https://www.rethinkdb.com/api/javascript/between/
What you need is the "during" keyword.
r.db("myDB").table("reservations").filter(function(doc){
return doc("room_id").eq("b1a7ddd3-ddfd-4624-8e85-79b47fb19f99")
.and( r.now().during(
r.ISO8601(doc("reservation_start"),{defaultTimezone:"+08:00"}),
r.ISO8601(doc("reservation_end"),{defaultTimezone:"+08:00"})))
}
)
edited Nov 17 '18 at 8:05
answered Nov 16 '18 at 15:54
taygetostaygetos
1,45321019
1,45321019
I tried, but I am getting errore: ISO 8601 string has no time zone, and no default time zone was provided
– Borgy Manotoy
Nov 16 '18 at 16:13
Can you send an example how your dates are stored?
– taygetos
Nov 16 '18 at 16:32
ex: "2018-11-12T08:30:00"
– Borgy Manotoy
Nov 16 '18 at 16:45
then you have to provide a defaultTimezone argument. eg.: "Z" for UTC. See my edit
– taygetos
Nov 16 '18 at 16:54
Hi @Peter, I tried and it did not return any error... but I did not get any result either. I updated the post and added a sample data from DB. I am thinking the problem is on the date format. I feel so dumb with rethinkDb :( it would be really fast to work this out if the project is in SQL.
– Borgy Manotoy
Nov 17 '18 at 3:32
|
show 3 more comments
I tried, but I am getting errore: ISO 8601 string has no time zone, and no default time zone was provided
– Borgy Manotoy
Nov 16 '18 at 16:13
Can you send an example how your dates are stored?
– taygetos
Nov 16 '18 at 16:32
ex: "2018-11-12T08:30:00"
– Borgy Manotoy
Nov 16 '18 at 16:45
then you have to provide a defaultTimezone argument. eg.: "Z" for UTC. See my edit
– taygetos
Nov 16 '18 at 16:54
Hi @Peter, I tried and it did not return any error... but I did not get any result either. I updated the post and added a sample data from DB. I am thinking the problem is on the date format. I feel so dumb with rethinkDb :( it would be really fast to work this out if the project is in SQL.
– Borgy Manotoy
Nov 17 '18 at 3:32
I tried, but I am getting error
e: ISO 8601 string has no time zone, and no default time zone was provided
– Borgy Manotoy
Nov 16 '18 at 16:13
I tried, but I am getting error
e: ISO 8601 string has no time zone, and no default time zone was provided
– Borgy Manotoy
Nov 16 '18 at 16:13
Can you send an example how your dates are stored?
– taygetos
Nov 16 '18 at 16:32
Can you send an example how your dates are stored?
– taygetos
Nov 16 '18 at 16:32
ex: "2018-11-12T08:30:00"
– Borgy Manotoy
Nov 16 '18 at 16:45
ex: "2018-11-12T08:30:00"
– Borgy Manotoy
Nov 16 '18 at 16:45
then you have to provide a defaultTimezone argument. eg.: "Z" for UTC. See my edit
– taygetos
Nov 16 '18 at 16:54
then you have to provide a defaultTimezone argument. eg.: "Z" for UTC. See my edit
– taygetos
Nov 16 '18 at 16:54
Hi @Peter, I tried and it did not return any error... but I did not get any result either. I updated the post and added a sample data from DB. I am thinking the problem is on the date format. I feel so dumb with rethinkDb :( it would be really fast to work this out if the project is in SQL.
– Borgy Manotoy
Nov 17 '18 at 3:32
Hi @Peter, I tried and it did not return any error... but I did not get any result either. I updated the post and added a sample data from DB. I am thinking the problem is on the date format. I feel so dumb with rethinkDb :( it would be really fast to work this out if the project is in SQL.
– Borgy Manotoy
Nov 17 '18 at 3:32
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53340607%2frethinkdb-query-current-date-time-between-two-date-columns%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown