{"id":3396,"date":"2016-03-15T02:08:12","date_gmt":"2016-03-15T02:08:12","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=3396"},"modified":"2016-03-15T02:08:12","modified_gmt":"2016-03-15T02:08:12","slug":"rethinkdb-fixing-error-e-no-attribute-last_name-object","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/rethinkdb-fixing-error-e-no-attribute-last_name-object\/","title":{"rendered":"RethinkDB: Fixing error &#8220;e: No attribute `last_name` in object:&#8221;"},"content":{"rendered":"<p>If you run a &#8216;map&#8217; in RethinkDB and an attribute is not found, you can get an error like so:<\/p>\n<pre lang=\"javascript\">\nr.db('test')\n .table('users')\n .map(\n  (doc) => {\n    return {\n      first_name: doc('first_name'),\n      last_name: doc('last_name')\n    }\n  }\n)\n<\/pre>\n<pre>\ne: No attribute `last_name` in object:\n<\/pre>\n<p>There are a couple ways to fix this, depending on your needs.<\/p>\n<p>You can remove objects without these attributes:<\/p>\n<pre lang=\"Javascript\">\nr.db('test').table('users')\n  .withFields(['first_name', 'last_name'])\n  .map(\n    (doc) => {\n      return {\n        first_name: doc('first_name'),\n        last_name: doc('last_name')\n      }\n    }\n  )\n<\/pre>\n<p>You can also fix this by setting default attributes with the &#8216;merge&#8217; function (this is similar to coalesce in SQL):<\/p>\n<pre lang=\"javascript\">\nr.db('test').table('users')\n  .map(\n    (doc) => { return r.expr(\n      {\n        first_name: '',\n        last_name: ''\n      }\n    ).merge(doc) }\n  )\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you run a &#8216;map&#8217; in RethinkDB and an attribute is not found, you can get an error like so: r.db(&#8216;test&#8217;) .table(&#8216;users&#8217;) .map( (doc) => { return { first_name: doc(&#8216;first_name&#8217;), last_name: doc(&#8216;last_name&#8217;) } } ) e: No attribute `last_name` in object: There are a couple ways to fix this, depending on your needs. You can &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/rethinkdb-fixing-error-e-no-attribute-last_name-object\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;RethinkDB: Fixing error &#8220;e: No attribute `last_name` in object:&#8221;&#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,462,466,523],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3396"}],"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=3396"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3396\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=3396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=3396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=3396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}