如果文档包含数组字段,则可以使用 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.