Is that possible to update Firestore document child array item only

随声附和 提交于 2021-01-29 17:39:11

问题


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

Is there any way to do that?


回答1:


According to the official documentation regarding updating array elements:

If your document contains an array field, you can use arrayUnion() and arrayRemove() to add and remove elements.

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.

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.



来源:https://stackoverflow.com/questions/60866021/is-that-possible-to-update-firestore-document-child-array-item-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!