senty senty - 5 months ago 33
Swift Question

Removing All Items Under A Node Firebase

I am trying to remove all the children under a node. Is there a way to delete all the items under a node? The structure is like:

lastMessages
- mainId
- timestampedId
- keys:values


What I want to do is, by using
mainId
, delete all the items under it. Actually there's only one
timestampedId
at a time as this is for lastMessages. That's why I thought I should delete all items under
mainId
just before writing my new value. Is there a way to achieve that; or is there any better ways than I thought?

let ref = Firebase(url: path)
let myRef = ref.childByAppendingPath(mainId)

// how to delete all items under myRef?

Answer

Simply call myRef.removeValue()

Explained in the docs

The simplest way to delete data is to call removeValue on a reference to the location of that data.

Comments