【问题标题】:How can read data of other users (not user.uid) from firestore如何从 firestore 读取其他用户(不是 user.uid)的数据
【发布时间】:2022-01-13 04:51:52
【问题描述】:

我想从 firestore 读取未经身份验证的用户的数据 收集位置是 users->swipes->id

我的尝试没有成功


const querySnapshot = await getDocs(collection(db, "users",id,"swipes"));
querySnapshot.forEach((doc) => {
  // doc.data() is never undefined for query doc snapshots
  console.log(doc.id, " => ", doc.data());
});

我想在滑动中读取 id,而不是从 user.uid 这里用户中有 3 个用户 如果想从 user.uid 读取,很容易

collection(db, "users",user.id,"swipes")

如果想从其他用户那里阅读 我很困惑 请帮忙

【问题讨论】:

    标签: javascript react-native google-cloud-firestore


    【解决方案1】:

    如果您想读取所有用户的swiped 子集合,您需要use a collection group query。这种类型的操作会读取所有具有特定名称的集合。

    在你的情况下是:

    const querySnapshot = await getDocs(collectionGroup(db, "swipes"));
    querySnapshot.forEach((doc) => {
      console.log(doc.id, " => ", doc.data());
    });
    

    【讨论】:

      猜你喜欢
      • 2020-05-11
      • 2018-11-06
      • 2019-09-18
      • 2020-09-26
      • 2020-12-30
      • 1970-01-01
      • 2022-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多