不能使用 firebase 引用数据类型来获取子集合

Posted

技术标签:

【中文标题】不能使用 firebase 引用数据类型来获取子集合【英文标题】:Cant use firebase reference data type to get subcollection 【发布时间】:2020-09-02 17:29:48 【问题描述】:

我正在尝试利用个人资料文档中的引用数据类型来访问所引用氏族文档的子集合。

    leaveClan() 
  console.log(this.getUser.displayName + " leaving " + this.getProfile);
  console.log(this.getProfile.data().clan);
  console.log(this.getProfile.data().clan.get().collection("members")
    .doc(this.getUser.uid));
  firebase
  .firestore().
  this.getProfile.data()
    .clan
    .get()
    .collection("members")
    .doc(this.getUser.uid)
    .delete()
    .then(() => 
      firebase
        .firestore()
        .collection("profiles")
        .doc(this.getUser.uid)
        .update(
          clan: null
        );
    );
,

【问题讨论】:

【参考方案1】:

好的,想通了。

  this.getProfile
    .data()
    .clan.get()
    .then(snapshot => 
      console.log(snapshot.data());
    );

只需 .get() 或您会执行的任何正常的 firebase 操作。带有引用的字段本质上也是文档引用。

我相信有一个更好的答案可以解释为什么这样有效或正确的术语但它有效,哈哈。

【讨论】:

以上是关于不能使用 firebase 引用数据类型来获取子集合的主要内容,如果未能解决你的问题,请参考以下文章