编辑:2018年9月12日
从开始August 28, 2018,现在可以更新数组成员。更多信息在这里。
如何在Firebase Firestore中添加/更新/删除数组元素?
简短的答案是您不能!如关于数组的官方文档中所示:
尽管
Cloud Firestore可以存储阵列,但可以it does not support查询阵列成员或更新单个阵列元素。
因此,当前无法在
Cloud Firestore数据库中添加,更新或删除单个数组元素。
看您的数据库架构,我可以说您没有任何数组。
availableProducts是一个对象,它下面有一个名为地图0,其保持两个String属性,spName和spPrice。如果要更新,假设价格,请使用以下代码:
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();documentReference ref = rootRef.collection("gdgsghs.cok").document("Shsheg");Map<String, Object> availableProducts = new HashMap<>();Map<String, Object> zeroMap = new HashMap<>();Map<String, Object> product = new HashMap<>();product.put("spPrice", 63.121);zeroMap.put("0", product);availableProducts.put("availableProducts", zeroMap);ref.set(availableProducts, SetOptions.merge());您的价格将从更新67.368为63.121。



