嗨,我正在构建某种投票系统,我想防止同一个用户在同一个帖子中投票。
let db = firebase.firestore();
var postRef = db.collection("posts").doc(this.pid);
postRef.update({
votes: firebase.firestore.FieldValue.increment(1)
});
var userRef = db.collection("users").doc(this.userId);
userRef.update({
votes: firebase.firestore.FieldValue.arrayUnion(this.pid)
});
//run this line if pid is added
this.votes = this.votes + 1;
只有在将 pid 添加到投票数组时,我才想增加投票。我想知道 arrayUnion 是否能够对此提供某种反馈,或者无论如何我可以做到这一点。
你可以看看这个帖子,你可以看到同一个人可以在同一个帖子上多次投票。