【问题标题】:AngularFire collectionGroup always throws error not a valid functionAngularFire collectionGroup 总是抛出错误不是一个有效的函数
【发布时间】:2021-04-07 01:22:41
【问题描述】:

我正在使用 Ionic 4,并且刚刚与 AngularFire 集成。集合和文档运行良好,但是我无法让 collectionGroup 函数正常工作 - 它总是给出该函数不存在的错误。

相关代码为:


this.user = this.firestore.collection('profile').doc(tok.uid);



 async StoreRecipe(recipe_name,meal) {

     var ua = await this.read_foods_meal(meal+1)
     console.log(meal);
     ua.subscribe( foods => { console.log(foods);
        foods.forEach(food =>  { this.user.collection('recipe').doc(recipe_name).collection('foods').add(food);} )
     });

 }
 
 async read_recipes() {
     
     var ua = await this.user.collectionGroup('recipe');
     return(ua);
 }

我已将名称中带有“Fire”的所有模块更新为最新版本: @角/火 @ionic-native/firebase-x 角火 火力基地 firebase 管理员

但错误仍然出现。另外,如果我尝试使用 .collection() 函数查询食谱集合,它只会返回一个空结果..即使“食谱”集合下有文档

【问题讨论】:

    标签: javascript firebase google-cloud-firestore ionic4 angularfire


    【解决方案1】:

    你的user 对象是firebase.firestore.DocumentReference 类的一个实例,它没有collectionGroup 方法。检查文档here

    如果您想跨多个集合运行查询,这些集合应该具有相同的名称,您可以使用firebase.firestore().collectionGroup() 方法。你可以在this link找到如何配置它。

    如果您只想获取recipe 集合中的所有文档,可以使用CollectionReference.get() 方法(documentation)。

    【讨论】:

      猜你喜欢
      • 2020-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-24
      • 2021-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多