[英]How to add or edit specific value within a map on a firestore document?
I have aa map within a firestore document that looks like this:我在 Firestore 文档中有一个 map,如下所示:
Right now I am confused on how to:现在我很困惑如何:
I thought Update() would be my best option based on the documentation:根据文档,我认为 Update() 将是我的最佳选择:
Set() in firestore:在 Firestore 中设置():
To create or overwrite a single document, use the set() method:要创建或覆盖单个文档,请使用 set() 方法:
Update() in firestore: Firestore 中的 Update():
To update some fields of a document without overwriting the entire document, use the update() method:要更新文档的某些字段而不覆盖整个文档,请使用 update() 方法:
So I want to update just my inPack map.所以我只想更新我的 inPack map。 I am doing that with this code:我正在使用以下代码执行此操作:
db
.collection('GearLockerItems')
.doc(doc.reference.id)
.update(
{
'inPack': {packID: false},
},
);
My issue is that it is overwriting the valueId and not adding a new valueID.我的问题是它覆盖了 valueId 而没有添加新的 valueID。 So I am updating the inPack by overwriting the entire thing.所以我通过覆盖整个东西来更新 inPack。 I think I am not getting down to the next level and am stuck.我认为我没有达到下一个水平并且被卡住了。
Use dot notation as follows:使用点符号如下:
db
.collection('GearLockerItems')
.doc(doc.reference.id)
.update({'inPack.$packId': false},
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.