如何解决每个用户的Firebase日志读取数
我有一个数据库,其中包含使用平台的每个人的文档。我想存储每个人要花费多少读物。最好的方法是什么?
解决方法
我不确定在Firebase分析中是否可行,但是您可以通过编程轻松地做到这一点:
//this function will reach out to a collection called usersUsage which has documents with IDs that are the users IDs. Then this function will increment a field called readCounts by incrementValue.
const userRead = (userId,incrementValue) => {
const increment = firebase.firestore.FieldValue.increment(incrementValue);
db.collection("usersUsage").doc(userId).update({
readCounts: increment
})
}
这适用于以这种方式阅读文档:
db.collection('cities').get().forEach(doc => {
console.log(doc.id,'=>',doc.data());
const userID = USER_ID;
const incrementvalue = 1;
userRead(userID,incrementvalue)
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。