我尝试将Map项添加到我的Array的某个位置。为此,我尝试了以下代码:
String userid =FirebaseAuth.getInstance().getCurrentUser().getUid();
DocumentReference washingtonRef = db.collection("Users").document(userid);
// Atomically add a new region to the "regions" array field.
washingtonRef.update("shoppingLists[0]", FieldValue.arrayUnion("greater_virginia"));
}下面是我必须添加一个值的结构:At this point i have to add the value
发布于 2019-01-19 04:56:11
你不能像这样用Firestore来索引数组字段。您可以使用arrayUnion和arrayRemove按值添加或删除列表类型字段的元素,但不能指定该项在数组中的位置。如果您需要更多地控制数组中元素的顺序,则必须首先读取文档,修改内存中的数组,然后将该字段更新回文档中。
https://stackoverflow.com/questions/54261098
复制相似问题