是否可以仅更新Firestore文档子数组项 [英] Is that possible to update Firestore document child array item only

查看:40
本文介绍了是否可以仅更新Firestore文档子数组项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要增加或减少提交的 maxQty ,并且在下面的图像中添加了数据结构.

I need to increment or decrement filed maxQty and the data structure is added in the below images.

带有红色标记的图像已归档,我添加了另一个图像以了解数据结构

Image with the red mark is the filed and I added another image to understand the data structure

有什么办法吗?

推荐答案

根据有关

如果文档包含数组字段,则可以使用 arrayUnion() arrayRemove()添加和删除元素.

不幸的是, arrayUnion()不适用于您的用例,因为您的 businessCard 数组包含对象而不是字符串.有两种选择,一种是读取整个数组,增加 maxQty ,然后将文档写回到服务器上.第二个方法是在 Map 的帮助下更新文档,方法是将要更改的每个字段的值手动复制到文档中.

Unfortunately, arrayUnion() does not apply to your use-case, as your businessCard array contains objects and not strings. There are two options, one would be to read the entire array, increase the maxQty, and then write the document back on the server. The second one would be to update the document with the help of a Map by manually copying values into it for each of the fields you want to change.

请注意,更新操作与Java POJO对象发生的自动字段映射不兼容.您只能使用Map对象.

Please also note that the update operation is not compatible with the automatic field mapping that occurs with Java POJO objects. You are allowed only to use Map objects.

这篇关于是否可以仅更新Firestore文档子数组项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆