使用 db.collection('users').get() 获取 Firestore 集合中的所有数据。

您可以将 .where() 方法留空,以便获取集合中的所有数据。请参考下面的修改后的代码:

db.collection('users').get()
  .then((querySnapshot) => {
    querySnapshot.forEach((doc) => {
      console.log(doc.id, ' => ', doc.data());
    });
  })
  .catch((error) => {
    console.log('Error getting documents: ', error);
  });

这将返回集合中所有文档的查询快照 (querySnapshot),然后您可以使用 .forEach() 方法遍历每个文档,并输出其 ID 和数据。

如何使用 Firestore 获取集合中所有数据

原文地址: https://www.cveoy.top/t/topic/qpyz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录