rethinkdb / rethinkdb_rebirth

The open-source database for the realtime web.
https://rethinkdb.com
Other
999 stars 42 forks source link

How to update multiple values of a certain type? #60

Closed Andre601 closed 6 years ago

Andre601 commented 6 years ago

I want to change some values, that are stored in RethinkDB. The issue is, that there are multiple entries with different tables and such and I don't really go through each one by one to update the values. I also only want to change a value, if the old one is a certain one.

Example: I have a table, where (after the ID) three values are stored: message, color and name. Now I want to update all the values in color to green, but only if the current value of that entry is color_green. Is there a way, to achieve this (tl;dr a advanced filter and replace-method.)?

ChrisTalman commented 6 years ago

If I understand you correctly, this could be achieved using a predicate function. For instance, in JavaScript:

r
    .table('Messages')
    .filter(message => message('color').eq('color_green'))
    .update('green')

There's some examples of this in the documentation. The query language is very powerful for operations like this.

Andre601 commented 6 years ago

ok. I'll take a look at that. thanks for the help.