Fixing “cannot convert number to sequence” in RethinkDB
If you don’t use the correct string of predicates in RethinkDB, you can get an error like this:
Server error:
e: Cannot convert NUMBER to SEQUENCE in: r.db("test").table("users").filter(function(var_229) { return var_229("user_name").match("test "); }).group("first_name").count().map({"first_name": r.row("group"), "val": r.row("reduction")}) ^^^^^^^
Here is an example of a query that causes this:
r.db('test') .table('users') .filter( (x) => x('user_name').match('test ') ) .group('first_name') .count() .map({ first_name: r.row('group'), val: r.row('reduction') }) |
The problem with this query is that the output of the grouped “count” is not the same datatype as a regular table. To convert it back, you need to add an additional “ungroup”:
r.db('test') .table('users') .filter( (x) => x('user_name').match('test ') ) .group('first_name') .count() .ungroup() .map( { first_name: r.row('group'), val: r.row('reduction') }) |
Interested in JavaScript? I send out weekly, personalized emails with articles and conference talks. Click here to see an example and subscribe.
Leave a Reply
Want to join the discussion?Feel free to contribute!