Most efficient way to select all documents about users from a specific source?

I have a purchases table.

I want to get all documents from users that have a source of “twitter”.

So the user’s table has source.

Getting all users that have source: “twitter” and then sending that list of userIds to find() on the purchases table does not seem very efficient.

The only other option I can think of is to copy the user’s source field to all the purchase documents, which does not feel very elegant, so I’m sure there’s a better way.

Thanks for any help!

Better or not, depends on what you want. You either store the source together or in a separate collection.

If the user source never changes, why not store it in the purchase info?

1 Like

It seems like a waste - extra storage, since it’s already stored in the user table.

I think I may be able to do what I need with a lookup aggregation?

Aggregation can work. It’s just slower.