简体   繁体   English

如何更新 Firestore 中文档地图中现有的字段

[英]How to update a field existing inside map of document in Firestore

I've kinda figured out that we can update just one field inside the map of the document我有点想通了,我们可以只更新文档地图中的一个字段

在此处输入图片说明

Like here I can add one more field to courses key, like就像在这里,我可以在课程键中再添加一个字段,例如

Map<String, Object> nested = new HashMap(){};
nested.add("sample field inside courses");

and passing it to another like并将其传递给另一个人

Map<String, Object> courses = new HashMap(){};
courses.add();

Q. How can I update the value of abbreviation_color which is the last field in the above image?问:如何更新上图中最后一个字段abbreviation_color的值?

Here's my test document:这是我的测试文档:

1


If I now want to update "Test2" I simply call...如果我现在想更新“Test2”,我只需调用...

yourDocumentReference.update("a.b2.c2", "New Value")

which results in this:这导致:


2


Edit : It does not care if it contains spaces or not, if "b2" would be "b 2" you could easily call编辑:它不在乎它是否包含空格,如果“b2”将是“b 2”,您可以轻松调用

yourDocumentReference.update("a.b 2.c2", "New Value")

I hope I could help somebody!我希望我能帮助别人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM