我在 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" …Run Code Online (Sandbox Code Playgroud)