Select activities of following users

Hi i’m doing a project where user can follow other users and see the activities of them.
For now i’ ve done 2 collections that have this schema

Schema.Activity = new SimpleSchema({
  actionType: {
     type: Number
  userId: {
    type: String        
  createdAt: {
     type: Date

Schema.User = new SimpleSchema({
    followedBy: {   // array of user._id
         type: [String],
         optional: true

With this schema, How can i select the last activities of users that a user follows?
In sql it would be something like:

"SELECT actions.* FROM actions INNER JOIN users ON actions.userId = users._id 
WHERE " + currentUserId + " IN (users.followedBy) "

What is the better method for do it with meteor?


In your publication you could:

  • Query first to find all followedBy user IDs, then loop over the returned cursor using forEach, querying against the activity collection to load and return activity data.