RethinkDB : Convert String to Number (and vice versa)

We are currently experimenting with RethinkDB on a new project we are working on. The ease of use and functionality so far has been top notch. This project requires porting a few existing MySQL tables into RethinkDB, and we will share a few tricks we learn along the way.

The first tip comes to us via the RethinkDB team itself.

When we ported over our tables, all values were added as strings, and we needed to convert some of them back to integers. In our example, we stored a row day as an value, 0-6. We wanted to convert this back to an int so we could do comparision queries against it. Here's the easiest way to accomplish this.

r.table("hours")
 .update({
    day: r.row("day").coerceTo("NUMBER")
 });

This will coerce the value of each entry to a number, and re-save the row.

Small dog web development studio
View All Our Posts

Web application developers in western Washington, creating user centric web solutions for businesses of all shapes and sizes.

Our projects include ecommerce, event organization, user driven web applications and more.


Small Dog Studios, LLC. Small Dog Studios News