Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Firestore中使用Firestore管理用户状态_Javascript_Firebase_Google Cloud Firestore - Fatal编程技术网

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协议是无连接的,所以它没有内置这样的功能。这是可能的,但我建议首先通过使用上一段链接中所示的实时数据库来了解它的工作原理。

问题是什么?