简体   繁体   English

如何更新 firebase 列表中的字段?

[英]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.

相关问题 当我的应用程序被杀死时如何更新字段(Firebase) - How to update a field when my app is killed(Firebase) 我可以在 angular firebase 集合的数据字段内插入、更新和删除数组吗? - Can I insert, update and delete array inside a data field in angular firebase collection? 如何使用 collections 更新 firebase firestore 文档中的字段 - How to update field in the firebase firestore document using the collections 如何删除 Firebase Object map 中的深层嵌套字段 - How to delete a deeply nested field inside a Firebase Object map 如何动态更新Firebase中所有关联文档中的文档或字段? - How to dynamically update a document or field in all associated documents in Firebase? 如何在 firestore 字段中插入 firebase 存储图像 - How to insert firebase storage images inside firestore field 如何将 object 添加到 Firebase 字段集合中的数组? - How can I add an object to an array inside a Firebase Field Collection? Firebase on value change update list - Firebase on value change update list Firebase 函数:更新集合中的所有文档 - Firebase Functions: update all documents inside a collection REACT JS FIREBASE FIRESTORE- 我如何更新文档中的字段? - REACT JS FIREBASE FIRESTORE- how can i update my field in a document?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM