Search code examples
firebasefirebase-realtime-databasefirebase-cli

Firebase CLI delete vs Rest API update with null


Goal here to delete as fast as possible keeping Firebaes Realtime Database instance utilization under 100 %.

I have 360 GB data in Firebase Realtime Database. Now I want to delete most the data that is not need. I have script that is doing delete by using firebase database:remove /node1/child1 (https://firebase.googleblog.com/2019/03/large-deletes-in-realtime-database.html)

Node Structure

"node1":{
   "child1":{
    "thousand of child's node here i want to delete"
    }, 
    "child2":{
    "thousand of child's node here i want to delete"
    },
   "child3":{
    "child3 is required can not delete this one "
    }
}

I was thinking if I update path firebase database:remove /node1/child1 to null. Will it remove all the child of child 1? and difference between these two approaches?


Solution

  • You should use firebase database:remove, as detailed in this blog post. By just calling remove() or update(null), you will lock the database until all data is deleted, something that could be many minutes or even hours with a dataset that large.

    The CLI command will instead chunk and batch deletes into reasonable sizes, keeping your database utilization from being completely locked. In fact, with database:remove you don't need to manually batch -- you can just pass it the largest node that you need deleted and it will automatically take care of batching for you.