Question

I am selecting multiple documents from an array of keys using (as suggested in this answer):

r.expr([person-id1, person-id2, person-id3])
 .eqJoin(function(doc) { return doc; }, r.table("person"))
 .zip()

Then joining to a second table by

r.expr([person-id1, person-id2, person-id3])
 .eqJoin(function(doc) { return doc; }, r.table("person"))
 .zip()
 .eqJoin("company_id", r.table("employers"))
 .zip()

Which all works great. The only change I'd like to make to optimize the query, is that I only need the employer_name from the employers table, as there is a considerable size of data that is otherwise associated with an "employers" document. Because this query only consists of eqJoins(), and no "base" table, is there a way to accomplish it?

Was it helpful?

Solution

pluck can actually be chained to any stream. I'd do this like so:

r.expr([person-id1, person-id2, person-id3])
 .eqJoin(function(doc) { return doc; }, r.table("person"))
 .zip()
 .eqJoin("company_id", r.table("employers"))
 .pluck({"right" : "employer_name"}, "left")
 .zip()

That gives you all of the "left" value and only "employer_name" from the right value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top