Here's a solution I have working, from Gadi:
https://plus.google.com/u/0/107554020054962631548/posts
This appears to be a really bad idea for large #'s of shares i.e. over a few thousand, since Mongo has a maximum document size of 16Meg, so I figure with 100K users in the SharedBy array it will cause major performance issues. I'm going to work on getting it to work with references VS embedded way, as per this post: Meteor, One to Many Relationship & add field only to client side collection in Publish?
Below works, but will not be efficient due to the growing array of SharedBy users:
// includes a sharedBy: [userId1, userId2, etc...] field.
Posts = new Meteor.Collection('posts');
Meteor.publish('posts', function() {
var self = this;
var handle = Posts.find().observeChanges({
added: function(id, fields) {
fields.sharedByMe = _.contains(fields.sharedBy, self.userId);
delete(fields.sharedBy);
self.added('posts', id, fields);
},
changed: function(id, fields) {
if (fields.sharedBy) {
fields.sharedByMe = _.contains(fields.sharedBy, self.userId);
delete(fields.sharedBy);
}
self.changed('posts', id, fields);
},
removed: function(id) {
self.removed('posts', id);
},
});
// Stop observing cursor when client unsubscribes
self.onStop(function() {
handle.stop();
});
self.ready();
});