$inc on button click

#1

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}});
		},
})
#2

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

#3

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

#5

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

#6

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

1 Like