{"id":3276,"date":"2016-03-07T02:52:09","date_gmt":"2016-03-07T02:52:09","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=3276"},"modified":"2016-03-07T02:52:09","modified_gmt":"2016-03-07T02:52:09","slug":"fixing-cannot-convert-number-sequence-rethinkdb","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/fixing-cannot-convert-number-sequence-rethinkdb\/","title":{"rendered":"Fixing &#8220;cannot convert number to sequence&#8221; in RethinkDB"},"content":{"rendered":"<p>If you don&#8217;t use the correct string of predicates in RethinkDB, you can get an error like this:<\/p>\n<p class=\"error_title\">Server error:<\/p>\n<pre class=\"error error_details\">e: Cannot convert NUMBER to SEQUENCE in:\nr.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\")})\n^^^^^^^<\/pre>\n<p>Here is an example of a query that causes this:<\/p>\n<pre lang=\"javascript\">r.db('test')\n .table('users')\n .filter( (x) => x('user_name').match('test ') )\n .group('first_name')\n .count()\n .map({ first_name: r.row('group'), val: r.row('reduction') })\n<\/pre>\n<p>The problem with this query is that the output of the grouped &#8220;count&#8221; is not the same datatype as a regular table. To convert it back, you need to add an additional &#8220;ungroup&#8221;:<\/p>\n<pre lang=\"javascript\">r.db('test')\n .table('users')\n .filter( (x) => x('user_name').match('test ') )\n .group('first_name')\n .count()\n .ungroup()\n .map(\n   { \n    first_name: r.row('group'),\n    val: r.row('reduction') \n  })\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you don&#8217;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(&#8220;test&#8221;).table(&#8220;users&#8221;).filter(function(var_229) { return var_229(&#8220;user_name&#8221;).match(&#8220;test &#8220;); }).group(&#8220;first_name&#8221;).count().map({&#8220;first_name&#8221;: r.row(&#8220;group&#8221;), &#8220;val&#8221;: r.row(&#8220;reduction&#8221;)}) ^^^^^^^ Here is an example of a query that causes this: r.db(&#8216;test&#8217;) .table(&#8216;users&#8217;) .filter( (x) => x(&#8216;user_name&#8217;).match(&#8216;test &#8216;) ) &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/fixing-cannot-convert-number-sequence-rethinkdb\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fixing &#8220;cannot convert number to sequence&#8221; in RethinkDB&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[160,302,462,466,523],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3276"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=3276"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3276\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=3276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=3276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=3276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}