'Creating increment limit
Ok so I am making a like/dislike system for my website and I got it to work. The only problem is, is that a user can like something more than once, how do I stop this? heres my function
function thumbup(uid, s) {
const prevthumbs = s.thumbs
firebase.db.collection('users').doc(uid).update({
thumbs: prevthumbs + 1
})
}
How can I limit the increment to only one?
Solution 1:[1]
To limit how often the user can do something, use their UID as the key for the operation.
For example, if you don't have too many users, you can have a field likedBy in the document which is an array of the UIDs of the users who liked this user.
It's a bit unclear how to exactly implement it in your code for me, as you're already writing to a doc(uid), where usually the user is liking a post or something like that.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Frank van Puffelen |
