Migrating to RethinkDB 1.12
There are a number of breaking changes in RethinkDB 1.12 you should be aware of before migrating.
Data migration
First, make sure to go through the regular data migration process, since the 1.12 file format isn't compatible with file formats generated by previous versions of RethinkDB.
Then, replace group_by
and grouped_map_reduce
commands in your applications with the new group
command.
group_by
command
Migrating the Here is an example of an old-style group_by
query:
r.table('users').group_by('location', r.count('age'))
And here is how to write the same query in RethinkDB as of 1.12:
r.table('users').group('location').count('age')
Note that all commands chained after group
will operate on each group, not on the full resultset. To operate on the full resultset, first call ungroup
. For example, suppose you'd like to order the output of the previous query by the reduction. Here is how you'd do it in previous versions of RethinkDB:
r.table('users').group_by('location', r.count('age')).order_by('reduction')
And here is how to write the same query in RethinkDB as of 1.12:
r.table('users').group('location').count('age').ungroup().order_by('reduction')
grouped_map_reduce
command
Migrating the Here is an example of an old-style grouped_map_reduce
query:
r.table('users').grouped_map_reduce(lambda row: row['location'],
lambda row: 1,
lambda x, y: x + y)
And here is how to write the same query in RethinkDB as of 1.12:
r.table('users').group(lambda row: row['location']) \
.map(lambda row: 1) \
.reduce(lambda x, y: x + y)
If you'd like to order by groups or reductions, make sure to first run ungroup
:
r.table('users').group(lambda row: row['location']) \
.map(lambda row: 1) \
.reduce(lambda x, y: x + y) \
.ungroup().order_by('reduction')
merge
command
A note on the The merge
command now accepts a function as a possible argument. For example:
r.table('users').merge(lambda user: { 'age': user['age'] + 1 })
That means that in some cases old code that uses r.row
will error:
# Will error due to nested use of `r.row`
r.table("foo").map(r.row.merge({ 'full_name' : r.row["first_name"] + r.row["last_name"] }))
To fix the error, use functions instead:
r.table("foo").map(lambda row: row.merge({ 'full_name' : row["first_name"] + row["last_name"] }))
run
function call in Node.js
Migrating the Prior to RethinkDB 1.12 there were two ways to call run
on a query:
query.run(connection, callback)
query.run({connection: connection, useOutdated: true}, callback)
The second syntax has now been deprecated. Using it will print a warning -- instead use the following syntax:
query.run(connection, [options,] callback);
See #1890 for more information on this change.
For those of us dealing with nested calls to
r.row()
after updates tomerge
.Isn't the better way to rewrite this example something like the following:
Was it possible to call
.merge()
on a sequence prior to 1.12, or is that new?