Javascript 如何在Firestore中使用Firestore管理用户状态
我尝试使用状态系统,但关闭选项卡后,脚本无法工作。如何将状态更改为脱机Javascript 如何在Firestore中使用Firestore管理用户状态,javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,我尝试使用状态系统,但关闭选项卡后,脚本无法工作。如何将状态更改为脱机 const db = firebase.firestore(); const usersRef = db.collection('users'); // Get a reference to the Users collection; // Set the specific user's online status to true usersRef .doc(userId) .set({ online:
const db = firebase.firestore();
const usersRef = db.collection('users'); // Get a reference to the Users collection;
// Set the specific user's online status to true
usersRef
.doc(userId)
.set({
online: true,
}, { merge: true});
CloudFireStore没有内置跟踪用户状态的功能。因为它的有线协议是无连接的,所以它并不适合这种情况 如果您需要跟踪哪些用户在线,我强烈建议您从实时数据库开始。此数据库的API具有和的功能。通过将这两者结合起来,您可以构建一个相对简单的模型
如上所述,由于Firestore的wire协议是无连接的,所以它没有内置这样的功能。这是可能的,但我建议首先通过使用上一段链接中所示的实时数据库来了解它的工作原理。问题是什么?