2

I would like to run a query that gets all the documents that have a lastUpdateDate from a date provided until today.

lastUpdateDated is defined like

lastUpdateDate = new Date() -> Tue Jan 19 2016 20:45:32 GMT+00:00

The following works in the RethinkDB Admin console

r.db('water').table('ground_water').filter(function (test) {
  return test("lastUpdateDate").during(r.time(2015,1,1, 'Z'), r.now().date())
});

But here is the actual code (I have to do some processing on the date)

.table('ground_support_water_tests')
              .filter(function(test) {
                return test("lastUpdateDate").during(
                  r.time(2016,1,19, 'Z'),
                  r.now().date())
              })
              .run()
              .then((results) => {
                console.log(results);
                done(null, results);
              })
              .catch((err) => {console.log(err); });

This returns no errors or results. I obviously like to not hardcode the date there so I have some logic to make a new r.time(yyyy,dd,mm) but that gives me the same results as this hardcoded one.

Mike Fielden
  • 10,055
  • 14
  • 59
  • 99

1 Answers1

3

I think your query may contains some pitfalls.

First, I suggest you add rightBound: "closed" to option. Because you are comparing on date() and you don't care about time at all.

Second, I suggest you to change test("lastUpdateDate") -> test("lastUpdateDate").date() because you're removing time with date and it become Wed Jan 20 2016 00:00:00 GMT+00:00 while as your test("lastUpdateDate") is Wed Jan 20 2016 18:00:00 GMT+00:00 for example.

So let's try this:

.table('ground_support_water_tests')
              .filter(function(test) {
                return test("lastUpdateDate").date().during(
                  r.time(2016,1,19, 'Z'),
                  r.now().date())
              }, {rightBound: "closed"})
              .run()
              .then((results) => {
                console.log(results);
                done(null, results);
              })
              .catch((err) => {console.log(err); });

Update:

I tried using NodeJS with official drive:

var r = require('rethinkdb')

r.connect().then(function(conn) {
  r.table('t')
  .filter((test) => {
      return test("lastUpdateDate").date().during(r.time(2015,1,1, 'Z'), r.now().date(), {rightBound: "closed"})
  })
  .run(conn)
  .then((cursor) => { return cursor.toArray() })
  .then((data) => { console.log(data) })
})

On this date set:

[{
"id":  "4917c8a1-1639-400c-964c-458d58b5bfcc" ,
"lastUpdateDate": Wed Jan 20 2016 21:12:51 GMT+00:00
}]

The query returns properly data.

kureikain
  • 2,304
  • 2
  • 14
  • 9
  • Good advice thanks for the help. The above changes didnt fix it. Im using the `rethinkdbdash` driver. In the admin console both of our code works. – Mike Fielden Jan 20 '16 at 21:39
  • 1
    may you try switch to official driver and see if it's fixed then we can dive more? Also with this data, `{ "id": "4917c8a1-1639-400c-964c-458d58b5bfcc" , "lastUpdateDate": Wed Jan 20 2016 21:12:51 GMT+00:00 }`. On RethinkDB console, your query failed, my query works. That leads me to the answer... – kureikain Jan 20 '16 at 21:52
  • Just switched to the native driver and this works as expected. So the problem appears to be `rethinkdbdash`. – Mike Fielden Jan 20 '16 at 22:39