{"id":3291,"date":"2016-03-07T03:34:01","date_gmt":"2016-03-07T03:34:01","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=3291"},"modified":"2016-03-07T03:34:01","modified_gmt":"2016-03-07T03:34:01","slug":"fixing-expected-type-datum-found-selection-rethinkdb","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/fixing-expected-type-datum-found-selection-rethinkdb\/","title":{"rendered":"Fixing &#8220;Expected type DATUM but found SELECTION&#8221; in RethinkDB"},"content":{"rendered":"<p>If you run a RethinkDB query, you can get an error attempting to intersect two tables:<\/p>\n<pre lang=\"javascript\">r.db('test')\n .table('users')\n .filter( (x) => x('user_name').match('test ') )\n .setIntersection(\n   r.db('test')\n    .table('users')\n    .filter(\n      (x) =&gt; x('user_name').match('9')\n    )\n )\n<\/pre>\n<p>The error looks like so:<\/p>\n<pre>Expected type DATUM but found SELECTION\n<\/pre>\n<p>The reason you get this error is that you have attempted to intersect two tables, when the function expects two arrays.<\/p>\n<p>The simplest way to do this is to join the data on it&#8217;s IDs.<\/p>\n<pre lang=\"javascript\">r.db('test')\n .table('users')\n .eqJoin(\n     'id',\n     r.table('users')\n   )\n<\/pre>\n<p>If you actually want to do this on all columns, you&#8217;ll need to implement a more complex filter, that looks at each column.<\/p>\n<p>You can also get this error if you try to alias columns in the incorrect way:<\/p>\n<pre lang=\"javascript\">\nr.db('test')\n .table('salaries')\n .group('role')\n .avg('salary')\n .ungroup()\n .map({group: 'Title', reduction: 'Amount'})\n<\/pre>\n<p>Instead, you want this:<\/p>\n<pre lang=\"javascript\">\nr.db('test')\n .table('salaries')\n .group('role')\n .avg('salary')\n .ungroup()\n .map({\n   group: r.row('Title'), \n   reduction: r.row('Amount')\n  })\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you run a RethinkDB query, you can get an error attempting to intersect two tables: r.db(&#8216;test&#8217;) .table(&#8216;users&#8217;) .filter( (x) => x(&#8216;user_name&#8217;).match(&#8216;test &#8216;) ) .setIntersection( r.db(&#8216;test&#8217;) .table(&#8216;users&#8217;) .filter( (x) =&gt; x(&#8216;user_name&#8217;).match(&#8216;9&#8217;) ) ) The error looks like so: Expected type DATUM but found SELECTION The reason you get this error is that you have attempted &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/fixing-expected-type-datum-found-selection-rethinkdb\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fixing &#8220;Expected type DATUM but found SELECTION&#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],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3291"}],"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=3291"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3291\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=3291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=3291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=3291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}