问题
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()andarrayRemove()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