Reputation: 451
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?
Upvotes: 0
Views: 74
Reputation: 317372
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.
Upvotes: 1