我正在使用 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-admin
但错误仍然出现。此外,如果我尝试使用 .collection() 函数查询配方集合,它只会返回一个空结果 .. 即使“配方”集合下有文档
答案 0 :(得分:0)
您的 user
对象是 firebase.firestore.DocumentReference
类的一个实例,它没有 collectionGroup
方法。检查文档 here。
如果您想对各种集合运行查询,这些集合应该具有相同的名称,并且您可以使用 firebase.firestore().collectionGroup()
方法。您可以在 this link 中找到如何配置它。
如果您只想获取 recipe
集合中的所有文档,可以使用 CollectionReference.get()
方法 (documentation)。