RethinkDb equivalent for filter between dates
I am really new to ReThinkDB coming from MySQL and I have some tasks that uses ReThinkDB.
Now, I would like to implement something like...
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`))
ReThinkDB:
This is the equivalent query using filter()
, thanks to @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"))))
)
But I am not sure how to convert the two date range checks into multiple between.
Thanks!
mysql rethinkdb
add a comment |
I am really new to ReThinkDB coming from MySQL and I have some tasks that uses ReThinkDB.
Now, I would like to implement something like...
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`))
ReThinkDB:
This is the equivalent query using filter()
, thanks to @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"))))
)
But I am not sure how to convert the two date range checks into multiple between.
Thanks!
mysql rethinkdb
add a comment |
I am really new to ReThinkDB coming from MySQL and I have some tasks that uses ReThinkDB.
Now, I would like to implement something like...
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`))
ReThinkDB:
This is the equivalent query using filter()
, thanks to @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"))))
)
But I am not sure how to convert the two date range checks into multiple between.
Thanks!
mysql rethinkdb
I am really new to ReThinkDB coming from MySQL and I have some tasks that uses ReThinkDB.
Now, I would like to implement something like...
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`))
ReThinkDB:
This is the equivalent query using filter()
, thanks to @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"))))
)
But I am not sure how to convert the two date range checks into multiple between.
Thanks!
mysql rethinkdb
mysql rethinkdb
edited Nov 15 '18 at 8:41
Borgy Manotoy
asked Nov 14 '18 at 10:20
Borgy ManotoyBorgy Manotoy
1,0281121
1,0281121
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Depending on what format you store your dates:
Option 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'));
)
option 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")))
Alternative way for more performance:
create index on reservation date:
r.db("myDB").table("reservations").indexCreate("reservation_date")
then use the following query:
r.db("myDB").table('reservations')
.between("2018-11-10T18:15:31.000000Z",
"2018-11-20T18:15:31.000000Z", index: "reservation_date")
Thanks @Peter, I updated the query and now it uses 2 date range checks. I tried usingbetween()
and it works... but as for the requirement... it needs two checks...start
andend
.
– Borgy Manotoy
Nov 15 '18 at 8:15
btw, I am evading those withfunction(doc)
since I am not sure how to convert it into java expression.
– Borgy Manotoy
Nov 15 '18 at 8:17
Thanks @Peter, I got it working now using filter(), your answer works :)
– Borgy Manotoy
Nov 15 '18 at 8:37
add a comment |
Now I understand your problem a little better
First to convert your query to 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")))))
Now optimally You may want to use the room_id as a secondary index:
r.db("myDB").table("reservations").indexCreate("room_id")
And then you can use in your query as:
r.db("myDb").table("reservations")
.getAll("7cc8e51d-e3fa-4d84-b7e6-9ebf8975754a")
.optArg("index","room_id")
.filter(...)
"But I am not sure how to convert the two date range checks into
multiple between."
1.) Create a compound array index
r.db("myDb").table("reservations").indexCreate(
"reservation_date", [r.row("reservation_start"), r.row("reservation_end")]
2.) use the between query
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"
)
// note: now this gets tricky when you need the room id as well :)
add a comment |
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%2f53297844%2frethinkdb-equivalent-for-filter-between-dates%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Depending on what format you store your dates:
Option 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'));
)
option 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")))
Alternative way for more performance:
create index on reservation date:
r.db("myDB").table("reservations").indexCreate("reservation_date")
then use the following query:
r.db("myDB").table('reservations')
.between("2018-11-10T18:15:31.000000Z",
"2018-11-20T18:15:31.000000Z", index: "reservation_date")
Thanks @Peter, I updated the query and now it uses 2 date range checks. I tried usingbetween()
and it works... but as for the requirement... it needs two checks...start
andend
.
– Borgy Manotoy
Nov 15 '18 at 8:15
btw, I am evading those withfunction(doc)
since I am not sure how to convert it into java expression.
– Borgy Manotoy
Nov 15 '18 at 8:17
Thanks @Peter, I got it working now using filter(), your answer works :)
– Borgy Manotoy
Nov 15 '18 at 8:37
add a comment |
Depending on what format you store your dates:
Option 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'));
)
option 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")))
Alternative way for more performance:
create index on reservation date:
r.db("myDB").table("reservations").indexCreate("reservation_date")
then use the following query:
r.db("myDB").table('reservations')
.between("2018-11-10T18:15:31.000000Z",
"2018-11-20T18:15:31.000000Z", index: "reservation_date")
Thanks @Peter, I updated the query and now it uses 2 date range checks. I tried usingbetween()
and it works... but as for the requirement... it needs two checks...start
andend
.
– Borgy Manotoy
Nov 15 '18 at 8:15
btw, I am evading those withfunction(doc)
since I am not sure how to convert it into java expression.
– Borgy Manotoy
Nov 15 '18 at 8:17
Thanks @Peter, I got it working now using filter(), your answer works :)
– Borgy Manotoy
Nov 15 '18 at 8:37
add a comment |
Depending on what format you store your dates:
Option 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'));
)
option 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")))
Alternative way for more performance:
create index on reservation date:
r.db("myDB").table("reservations").indexCreate("reservation_date")
then use the following query:
r.db("myDB").table('reservations')
.between("2018-11-10T18:15:31.000000Z",
"2018-11-20T18:15:31.000000Z", index: "reservation_date")
Depending on what format you store your dates:
Option 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'));
)
option 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")))
Alternative way for more performance:
create index on reservation date:
r.db("myDB").table("reservations").indexCreate("reservation_date")
then use the following query:
r.db("myDB").table('reservations')
.between("2018-11-10T18:15:31.000000Z",
"2018-11-20T18:15:31.000000Z", index: "reservation_date")
edited Nov 14 '18 at 12:45
answered Nov 14 '18 at 12:30
taygetostaygetos
1,24311018
1,24311018
Thanks @Peter, I updated the query and now it uses 2 date range checks. I tried usingbetween()
and it works... but as for the requirement... it needs two checks...start
andend
.
– Borgy Manotoy
Nov 15 '18 at 8:15
btw, I am evading those withfunction(doc)
since I am not sure how to convert it into java expression.
– Borgy Manotoy
Nov 15 '18 at 8:17
Thanks @Peter, I got it working now using filter(), your answer works :)
– Borgy Manotoy
Nov 15 '18 at 8:37
add a comment |
Thanks @Peter, I updated the query and now it uses 2 date range checks. I tried usingbetween()
and it works... but as for the requirement... it needs two checks...start
andend
.
– Borgy Manotoy
Nov 15 '18 at 8:15
btw, I am evading those withfunction(doc)
since I am not sure how to convert it into java expression.
– Borgy Manotoy
Nov 15 '18 at 8:17
Thanks @Peter, I got it working now using filter(), your answer works :)
– Borgy Manotoy
Nov 15 '18 at 8:37
Thanks @Peter, I updated the query and now it uses 2 date range checks. I tried using
between()
and it works... but as for the requirement... it needs two checks... start
and end
.– Borgy Manotoy
Nov 15 '18 at 8:15
Thanks @Peter, I updated the query and now it uses 2 date range checks. I tried using
between()
and it works... but as for the requirement... it needs two checks... start
and end
.– Borgy Manotoy
Nov 15 '18 at 8:15
btw, I am evading those with
function(doc)
since I am not sure how to convert it into java expression.– Borgy Manotoy
Nov 15 '18 at 8:17
btw, I am evading those with
function(doc)
since I am not sure how to convert it into java expression.– Borgy Manotoy
Nov 15 '18 at 8:17
Thanks @Peter, I got it working now using filter(), your answer works :)
– Borgy Manotoy
Nov 15 '18 at 8:37
Thanks @Peter, I got it working now using filter(), your answer works :)
– Borgy Manotoy
Nov 15 '18 at 8:37
add a comment |
Now I understand your problem a little better
First to convert your query to 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")))))
Now optimally You may want to use the room_id as a secondary index:
r.db("myDB").table("reservations").indexCreate("room_id")
And then you can use in your query as:
r.db("myDb").table("reservations")
.getAll("7cc8e51d-e3fa-4d84-b7e6-9ebf8975754a")
.optArg("index","room_id")
.filter(...)
"But I am not sure how to convert the two date range checks into
multiple between."
1.) Create a compound array index
r.db("myDb").table("reservations").indexCreate(
"reservation_date", [r.row("reservation_start"), r.row("reservation_end")]
2.) use the between query
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"
)
// note: now this gets tricky when you need the room id as well :)
add a comment |
Now I understand your problem a little better
First to convert your query to 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")))))
Now optimally You may want to use the room_id as a secondary index:
r.db("myDB").table("reservations").indexCreate("room_id")
And then you can use in your query as:
r.db("myDb").table("reservations")
.getAll("7cc8e51d-e3fa-4d84-b7e6-9ebf8975754a")
.optArg("index","room_id")
.filter(...)
"But I am not sure how to convert the two date range checks into
multiple between."
1.) Create a compound array index
r.db("myDb").table("reservations").indexCreate(
"reservation_date", [r.row("reservation_start"), r.row("reservation_end")]
2.) use the between query
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"
)
// note: now this gets tricky when you need the room id as well :)
add a comment |
Now I understand your problem a little better
First to convert your query to 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")))))
Now optimally You may want to use the room_id as a secondary index:
r.db("myDB").table("reservations").indexCreate("room_id")
And then you can use in your query as:
r.db("myDb").table("reservations")
.getAll("7cc8e51d-e3fa-4d84-b7e6-9ebf8975754a")
.optArg("index","room_id")
.filter(...)
"But I am not sure how to convert the two date range checks into
multiple between."
1.) Create a compound array index
r.db("myDb").table("reservations").indexCreate(
"reservation_date", [r.row("reservation_start"), r.row("reservation_end")]
2.) use the between query
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"
)
// note: now this gets tricky when you need the room id as well :)
Now I understand your problem a little better
First to convert your query to 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")))))
Now optimally You may want to use the room_id as a secondary index:
r.db("myDB").table("reservations").indexCreate("room_id")
And then you can use in your query as:
r.db("myDb").table("reservations")
.getAll("7cc8e51d-e3fa-4d84-b7e6-9ebf8975754a")
.optArg("index","room_id")
.filter(...)
"But I am not sure how to convert the two date range checks into
multiple between."
1.) Create a compound array index
r.db("myDb").table("reservations").indexCreate(
"reservation_date", [r.row("reservation_start"), r.row("reservation_end")]
2.) use the between query
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"
)
// note: now this gets tricky when you need the room id as well :)
edited Nov 15 '18 at 9:16
answered Nov 15 '18 at 9:01
taygetostaygetos
1,24311018
1,24311018
add a comment |
add a comment |
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%2f53297844%2frethinkdb-equivalent-for-filter-between-dates%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