英文:
How to clear array in Firebase Cloud database?
问题
我在我的云数据库中有一个令牌数组。我想要清除它(保持一个空的数据库)。我尝试过:
connectedGroup.collection("cars").document(carName).update("tokens", FieldValue.arrayUnion());
它真的会清除数组吗?感觉有点奇怪,因为我以为 arrayUnion
需要一个对象。在数据库中清除数组内容的正确方法是什么?我还考虑过使用:
connectedGroup.collection("cars").document(carName).update("tokens", new ArrayList<>());
哪种方式更好?
英文:
I have a an array of tokens in my Cloud database. I want to clear it (keep an empty database). I tried:
connectedGroup.collection("cars").document(carName).update("tokens", FieldValue.arrayUnion());
Does it really cleans the array? It feels strange because I thought arrayUnion
is expecting an object. What is the proper way to clear array's content in the database? I also thought to use:
connectedGroup.collection("cars").document(carName).update("tokens", new ArrayList<>());
Which is better?
答案1
得分: 1
FieldValue.arrayUnion()
用于在数组字段中添加新元素,如其API文档所述。如果您想确保数组字段为空,只需像第二个示例中一样将空数组写入其中。
英文:
FieldValue.arrayUnion()
is used when you want to add new elements to an array field, as described in its API documentation. If you want to make sure an array field is empty, then just write an empty array to it as you are in the second example.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论