[solved] Users and Posts without join

I have tried a few solutions and they seem subpar. What I want to do is get all the posts from my database on a specific subject, and get all of the users who made the posts in the same subscription. The posts collection doesn’t have any user info other than an ID, because I didn’t want to store info like, name or avatar in the posts, because that data will most likely be changed at some time, making all of the old data stale.

I have a bit of a sql background so what I was looking for was a join, which does not exist in MongoDB. I found this link and it has some good info about possible solutions. Before I read that link, my first try was to use the posts cursor in the publication to get all of the user id’s and query the users collection and return them both from the publication. This seemed to work, but when a new user posts, their info isn’t published because the users cursor is based on an array, so it is not reactive. That was a bummer, as it seemed like the most logical way to solve the issue.

Currently I am having the client ask for a list of users. When the posts publication changes the user id is added to an array and that array is used to subscribe to the users. This solution works-ish (is always up to date at least) however there is a noticable latency problem. (the clients have to request the posts, wait for them, then request the users and wait)

Does anyone have any creative solutions to this problem?

Right now I’m using template level subscriptions for both users and posts. Would it be more logical to make that a global subscription so that the data doesn’t get dumped on page changes?

What are you guys doing about users and posts in your applications? Are you denormalizing?

Have you tried this :

Thanks for the tip. I got it implemented and functioning much better with your advice. Have you used this package in production?

I have just used it for some weeks.