How make leftJoin in Meteor


#1

Hello.
I know it’s popular question, but…
I have default users collections.
And Projects collection, wich contain field Access, with list of users id, whio can see this project.
How i can get list of users (name, avatar etc.) for each project?


#2

You can use something like reywood:composite, or even a “true” left join using the MongoDB aggregation pipeline with the $lookup operator.

Alternatively, consider cultofcoders:grapher for an alternative, high performance approach.


#3

Or just do two queries and combine in JavaScript using map/reduce to get what you want.


#4

That would be the low-performance, high-server-usage method, by the way. Because it actually needs n+1 queries if you don’t want to pull down everything from the collections, up to and including the kitchen sink.

Just sayin’.


#5

but it may be a trivial difference, depending on the size of your data, or if you want to maintain reactivity, so may be worth considering. Can you get reactivity working with aggregation these days?


#6

Reactive aggregation using packages has been available for years. I’ve recently forked the jcbernack:reactive-aggregate package to remove the dependency on meteorhacks:aggregate and use modern async/await via the underlying npm MongoDB library. Check out tunguska:reactive-aggregate, if you’re interested.

Both these packages work well for reactivity and can have some optimisations applied to help alleviate unnecessary re-running.