0

I'm trying to run a ReQL query to fetch the data between 2 epoch times, i have a field called "lastUpdatedDttm" using which i'm trying to run the query like below. The lastUpdatedDttm field type is "number" and is just new date().getTime()

r.db('my_db').table('my_table').getAll('/mypath', { 
index: 'path' }) .filter(r.row('updatedBy').eq('id').and(r.row('lastUpdatedDttm').during(1512864000000, 1513209600000)))

The above query returns error, e: Not a TIME pseudotype:

Am i missing something in the query?

Sai
  • 1,790
  • 5
  • 29
  • 51

1 Answers1

0

i believe duration needs time objects as arguments so you need to use the epochTime method to convert your times, so

r.db('my_db').table('my_table').getAll('/mypath', { index: 'path' })
  .filter(
    r.row('updatedBy').eq(id)
      .and(
        r.row('lastUpdatedDttm')
          .during(
            r.epochTime(1512864000000 / 1000),
            r.epochTime(1513209600000 / 1000)
          )
      )
    )

you should also make sure lastUpdatedDttm is stored as a date

if you are storing lastUpdatedDttm as a number generated by new Date().getTime() you can do

r.db('my_db').table('my_table').getAll('/mypath', { index: 'path' })
  .filter(record => {
    return record('updatedBy').eq(id).and(
      r.epochTime(record('lastUpdatedDttm').div(1000))
        .during(
          r.epochTime(1512864000000 / 1000),
          r.epochTime(1513209600000 / 1000)
        )
    )
})
vbranden
  • 5,814
  • 2
  • 22
  • 15
  • still no luck, getting the same error e: Not a TIME pseudotype:, the lastUpdatedDttm type is type.number() and is stored as new Date().getTime() – Sai Dec 15 '17 at 17:47
  • new Date().getTime() is not a date, its a number. If you want to store the current date in the database you should be using database time with `r.now()` otherwise you need to store it with `r.epochTime(new Date().getTime())` or shorter `r.epochTime(Date.now())` – vbranden Dec 15 '17 at 17:50
  • got you, as you said earlier, '.during' only accepts time objects whereas when i run the query using '.gt(1512864000000)' it returns just fine. – Sai Dec 15 '17 at 17:57
  • tried the query like below using .gt, r.db('my_db') .table('my_table') .getAll('/mypath', { index: 'path' }) .filter( r.row('updatedBy') .eq('id') .and( r.row('lastUpdatedDttm') .gt(1512864000000) ) ) – Sai Dec 15 '17 at 17:59
  • see my updated answer where the unix times are converted – vbranden Dec 15 '17 at 18:00