小编Mar*_*yne的帖子

如何获取firestore collectionGroup查询的父文档?

我正在尝试获取我得到的所有子集合查询的父文档,因此我的数据库看起来像这样

/生产/id/位置/id/positionhistory

我获得了职位历史的所有文件,但我还需要一些职位和生产的数据。我希望是否有一种方法可以在 collectionGroup 查询中获取父母的文档。我也在使用 firestore v9。

const getHistory = async () => {
  setLoading(true);
  try {
    const userHisRef = query(
      collectionGroup(db, "positionhistory"),
      where("userid", "==", currentUser.uid)
    );
    const querySnapshot = await getDocs(userHisRef);
    let arr = [];
    querySnapshot.forEach((doc) => {
      console.log(doc.id);
      arr.push(doc.id);
    });

    setLoading(false);
  } catch (err) {
    console.log(err);
    setLoading(false);
    
  }
};
getHistory();
Run Code Online (Sandbox Code Playgroud)

javascript firebase google-cloud-platform google-cloud-firestore

4
推荐指数
1
解决办法
3843
查看次数