Skip to content

Instantly share code, notes, and snippets.

@brandon-beacher
Last active July 22, 2016 11:59
Show Gist options
  • Save brandon-beacher/0b684f471a4e279dc77e to your computer and use it in GitHub Desktop.
Save brandon-beacher/0b684f471a4e279dc77e to your computer and use it in GitHub Desktop.
left outer join in RethinkDB using javascript syntax
r.db("gather").table("contacts").filter({Company: "yiq5yon7"}).concatMap(function(contact) {
return r.db("gather").table("accounts").getAll(contact("Account").default("")).coerceTo("array").do(function(accounts) {
return r.branch(
accounts.isEmpty(),
[ { left: contact, right: null } ],
accounts.map(function(account) {
return { left: contact, right: account }
})
);
});
});
@hyperh
Copy link

hyperh commented Jul 22, 2016

Thanks! This totally helped, because the official docs (here https://www.rethinkdb.com/docs/sql-to-reql/javascript/) weren't working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment