Given the following Mongo collections:
- A large collection of articles which hold the ID of the user who wrote them.
- A large collection of users, each of which can 'follow' a large number of other users.
My objective is to get a cursor to all the articles written by any one of the authors that a given user is following.
Currently I have to do this in several steps:
- Find() the authors that the user is following
- Turn this result into an array of IDs
- Find the articles written by any of the users in that array (using $in).
Step 2 is highly inefficient. I'm currently fetching the entire result, reforming it into an array, and then sending it back to the database as part of the query. All this has to be be done in Javascript (running on Meteor/Node.js).
Is there a better solution?