如何使用 Angular Firestore 创建和更新子集合?

Mar*_*ork 4 javascript angularfire2 angular google-cloud-firestore

我在 Firestore 中创建了一个集合“Person”。我能够从代码创建文档和字段。

ngOnInit() {
this.personCol = this.afs.collection('person');
//snapshotChanges is used to retreive the document data and other metadata, which includes the ID
//we need ID to edit or delete a record
this.person = this.personCol.snapshotChanges()
  .map(actions => {
   return actions.map(a => {
     const data = a.payload.doc.data() as Person;
     const id = a.payload.doc.id;
     return { id, data };
   });
  });}
addPerson() {
this.afs.collection('person').add({
  'name': this.name,
  'age': this.age,
});}
getPerson(PersonId) {
this.personDoc = this.afs.doc('person/'+personId);
this.singlePerson = this.personDoc.valueChanges();
Run Code Online (Sandbox Code Playgroud)

}

现在我想添加该人借阅的书籍列表:

Person: 
{Name: "John"
 Age: 32 
 Books: {Title: "First book", Author: "Some author"
         Title: "Second book" Author: "Another author"},
{Name: "Anne"
 Age: 21
 Books: {Title: "How to... book", Author: "Author Name"
         Title: "Flowers book" Author: "Another author"} 
Run Code Online (Sandbox Code Playgroud)

如何Books使用 Angular 创建子集合?如何访问Books子集合以更新titleauthor来自代码?

Fra*_*len 6

要访问特定人员的图书子集合:

this.personBooks = this.afs.collection('person/'+personId+'/Books');
Run Code Online (Sandbox Code Playgroud)