3

I have imported a table from MySQL into RethinkDB, and it worked well. Now I am trying to figure out how to update my previous MySQL timestamp fields into Time objects in RethinkDB, with no success.

Using the query explorer:

r.table('users').withFields('last_login_at').update({ last_login_at: new Date(r.row('last_login_at')) });

-- Result --

JavaScript error:

RangeError: Invalid time value
Dustin Brownell
  • 817
  • 7
  • 10

1 Answers1

2

Assuming your dates are currently stored as strings? You dont say...

Here is some sample data...

[
  {"date":"2014-12-11T20:00:41.000Z","id":"cd6e152a-9df7-49bc-a887-b43ef5cb559d","name":"dude2"},
  {"date":"2014-12-11T21:00:41.000Z","id":"5f5f2cef-9853-4400-ad6e-4fa26ff5469b","name":"dude1"},
  {"date":"2014-12-11T19:00:41.000Z","id":"651cef31-4560-4bca-b458-ce43aa8c0c90","name":"dude3"}
]

With this query...

r.db('mydb').table('test').update({ date: r.ISO8601(r.row('date')) });

Data becomes...

[
  {"date":{"$reql_type$":"TIME","epoch_time":1418328041,"timezone":"+00:00"},"id":"cd6e152a-9df7-49bc-a887-b43ef5cb559d","name":"dude2"},
  {"date":{"$reql_type$":"TIME","epoch_time":1418331641,"timezone":"+00:00"},"id":"5f5f2cef-9853-4400-ad6e-4fa26ff5469b","name":"dude1"},
  {"date":{"$reql_type$":"TIME","epoch_time":1418324441,"timezone":"+00:00"},"id":"651cef31-4560-4bca-b458-ce43aa8c0c90","name":"dude3"}
]

Hope that helps.

InternalFX
  • 1,475
  • 12
  • 14