$inc on button click

I cannot seem to get around this seemingly simple issue. I have been trying to increment +1 whenever the user clicks on the like button. However, it doesn’t seem to be working. What am I missing?

I want the result to be updated on the MongoDB.

Template.explore.events({
	"click #love": function() {
	Meteor.users.update({_id:UserId}, {$inc: {'profile.loveScore': +1}});
		},
})

Your $inc operator is wrong, use 1 instead of +1.

Take a look at Meteor and MongoDB documentations :

https://docs.mongodb.com/manual/reference/operator/update/inc/index.html

I have removed the + However, it still doesn’t seem to be updating.

Have you forgit to declare the allow/deny rules on the collection instance? I used to forgot that one too :slight_smile:

Maybe you could share what solution worked for you, it could help other people searching for a similar problem :wink: .

1 Like