J. Doe
J. Doe

Reputation: 13033

FieldValue.delete() can only appear at the top level of your update data - Firestore

This is my database:

enter image description here

How can I delete key "2" in lotteryIDs under the map private? I tried this:

db.collection("users").document(currentUser.uid).updateData([
"private": ["lotteryIDs" : ["2" : FieldValue.delete()]]
])

And now I got the error as described in the title. Using:

"private/lotteryIDs/\(id)": FieldValue.delete

obviously did not work out well. I could not find it in the docs where they only explain how to delete top-level fields, not fields within objects.

Upvotes: 6

Views: 3713

Answers (1)

Michael Lehenbauer
Michael Lehenbauer

Reputation: 16309

You should be able to use a dotted field path with updateData:

db.collection("users").document(currentUser.uid).updateData([
"private.lotteryIDs.2" : FieldValue.delete()])

Upvotes: 16

Related Questions