如何在文档+;angularfire2+;角度5

如何在文档+;angularfire2+;角度5,angular,firebase-realtime-database,google-cloud-functions,angular5,angularfire2,Angular,Firebase Realtime Database,Google Cloud Functions,Angular5,Angularfire2,我想在一个文档中添加一个集合,我在google上搜索了很多,但没有找到任何合适的解析。 甚至搜索了firebase文档,但我的查询没有结果 我尝试了不同的方法将集合添加到文档中,下面是我的代码示例 let tmpObj = { title: vm.pageTitle, creationDate: dt.getTime() }; this.db.collection("pages").doc("page_"+this.bookId).collection("Test").add(tmpOb

我想在一个文档中添加一个集合,我在google上搜索了很多,但没有找到任何合适的解析。 甚至搜索了firebase文档,但我的查询没有结果

我尝试了不同的方法将集合添加到文档中,下面是我的代码示例

let tmpObj = {
  title: vm.pageTitle,
  creationDate: dt.getTime()
};
this.db.collection("pages").doc("page_"+this.bookId).collection("Test").add(tmpObj);
还有,我甚至试过

let mainCollection = this.db.collection("pages").doc("page_"+ this.bookId).collection("test").valueChanges();
let subcollection = mainCollection.push(tmpObj);
// This is also not working for me
在上述代码中,db公共db:AngularFirestore 请查找所附的屏幕截图,以查看我要添加收藏的位置(突出显示)

我需要的结构是收集->文档->收集

请尝试:

this.db.collection(`pages/page_${this.bookId}/Test`).add(tmpOb);

下面的代码满足了我的需要,有了这些代码,我现在可以在每个文档中创建尽可能多的嵌套集合

tmpObj = {
    title: vm.pageTitle,
    desc: description,
    creationDate: dt.getTime()
  }

this.db.collection('pages').doc("pages_"+ this.bookId).collection<any>("AllPages").doc("page_"+ dt.getTime()).set({tmpObj})
.then(function() {
    console.log("Pages Created successfully!");
})
.catch(function(error) {
    console.error("Error writing document: ", error);
});
tmpObj={
标题:vm.pageTitle,
描述:,
creationDate:dt.getTime()
}
this.db.collection('pages').doc('pages_'+this.bookId.).collection('AllPages').doc('pages_'+dt.getTime()).set({tmpObj})
.然后(函数(){
log(“页面创建成功!”);
})
.catch(函数(错误){
console.error(“编写文档时出错:”,错误);
});

请尝试此模板

await this.db.collection('mainCollectionName').doc("mainDocID").set(obj);
await this.db.doc('mainCollectionName/mainDocID').collection('subCollectionName').doc('subDocumentID').set(subCollectionObj);

你收到控制台错误了吗?@guruprasadao我没有收到任何错误扫描你
订阅
子集合
,看看你得到了什么结果?你的代码应该已经运行了,添加一个
(“测试”).add(tmpObj).catch()
并检查是否有错误。您还需要检查firestore规则。