Can someone indicate whether the publish function needs monogdb's forEach
operation, meteors' this.added or Meteor's observe function.
The current publish function works but not sure if this is reactive which is my main concern.
Will the forEach function operate for every new document added into the Blogs Collection?
user1 _id
is embedded in several documents in a Blogs
Collection like this:
creator: user1's_id
Within this Blog document there is also a field for one other user 'collaborator:
creator: user1's_id
collaborator: anotherUser_id
User1 may be the creator of hundred Blog documents but the collaborator will always be a different for every Blog document.
I would like to create the Meteor.publish function for the user who is the creator
and return the following two cursors
- all the Blog documents for which user1 is the
creator
all the Meteor.users() who are the
collaborator
Meteor.publish('creatorBlogContext', function() { var user = Meteor.users.findOne(this.userId) if (user && user.profile.userType === 'creator') { var blogsCursor = Blogs.find({'creator': user._id}); //returns all blog docs the user has created. var userIdsArray = [] Blogs.find({'creator': user._id}).forEach(function(doc) { userIdsArray.push(doc.collaborator) }) var usersCursor = Meteor.users.find({_id: {$in: userIdsArray}}) return [blogsCursor, usersCursor]; } });
Will the above function reactively re-run when a new Blog document so the forEach function pushes out the Meteor.user of the collaborator?
Note: I don't wish to user iron router and do a findOne in the publish function depending on which blog the creator is viewing. I wish to do this the core meteor way, so no packages suggestions please.
Thank you and please ask for further information if I have not been clear.