[英]How to update a field inside a list in firebase?
I have this collection in Firebase我在 Firebase 有这个收藏
I have tried to modify the value within the map notes of a specific subject, I could not do it and I have tried in several ways without success I would really appreciate a little help.我试图修改特定主题的 map 注释中的值,我做不到,我尝试了几种方法都没有成功,我真的很感激你的帮助。
I get the data in that way, but I can not update that data.我以这种方式获取数据,但无法更新该数据。
this.firestore.collection('school').doc('254')
.get().toPromise().then(doc => {
if (doc.exists) {
const student = doc.data().class.find(value => {
return value.name === 'john';
});
console.log('student', student);
/*
Here edit student.notes.math = newValue
*/
}
});
PD: I'm currently work with Angular 7. PD:我目前与 Angular 7 一起工作。
I don't see that your code attempts to update the document that you found.我没有看到您的代码试图更新您找到的文档。 Changing the data in memory doesn't change the contents of the document.
更改 memory 中的数据不会更改文档的内容。 You will have to write additional code to update the document with your changes to the class field.
您将必须编写额外的代码,以使用您对 class 字段的更改来更新文档。
See:看:
this.firestore
.collection('school')
.doc('254')
.update("class", NEW_FIELD_CONTENTS)
You will need to provide the entire contents of the updated class field.您将需要提供更新后的 class 字段的全部内容。 Firestore doesn't have any operations that let you update an array item at a specific index.
Firestore 没有任何可让您更新特定索引处的数组项的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.