Why doesn't Reactivity propagate to all users

I have a page where user A can ‘like’ another user B’s comment. So when a comment is liked it updated that user B’s ‘likes’ field and as expected reactively updated the number of likes for that comment on user B’s page.

HOWEVER user A does not experience the reactivity to show the updated like counter to, even though we know the ‘likes’ field has been updated.

So how can all like counters be updated reactively for all users who are viewing that comment, rather than having to refresh the actual page.

In my template this is my like button:

<button type="button" class="btn btn-default btn-sm likeBtn fontScale" title="Likes"><i class="fa fa-heart fa-2x"><span class="badge fontScale">{{likes.length}}</span></i></button>

The client.js file:

"click .likeBtn": function(event){
var user = $(event.currentTarget).closest('.shadow').find('.imgRef1').val();
var item = $(event.currentTarget).closest('.shadow').find('.imgRef').val();

Meteor.call('like', user, item, (error, result) => {
    if (!error) {

The method like is in a methods.js file which is in a lib file:

   //console.log('USER: ' + user + ' and Image: ' + item);
    Meteor.users.update({_id: user, 'ImagesUploaded.key':item}, {$push: {'ImagesUploaded.$.likes': Meteor.userId()}});

Where does that come from? You want to know why this part of the code is not reactive, yet you pasted everything but this.

My bad…I just realised that I set my mongo query to reactive:false - hence the issue.

1 Like