How to remove multiple children in one call - Realtime Firebase

January 25, 2022, at 3:50 PM

I wan to delete multiple children with known key. I searched all the related posts but it doesn't seem to work. It shows red bracket.

Below is my code which i refer from other posts:

var updates = { } 
for(i in removedProductVariationIdList){
    updates["user/$i"] = null


Firebase Structure (I want to remove 3, 4 under Product_Variation for example, which i know the key) :

Answer 1

Java doesn't support template literals with the $i notation in regular strings, as far as I know. The simplest way to build a map with the null values:

Map<String, Object> updates = new HashMap<>();
for(i in removedProductVariationIdList){
    updates.put("user"+i, null);

Also see:

  • Firebase Transactions of Add, Delete on Multiple Nodes
Answer 2

You need to declare values as a map.

val map = mutableMapOf<String, Any?>()
Answer 3


With the help from Frank's reference link and danartillaga answers, below is my code in Kotlin which works:

val productVariationRef = FirebaseDatabase.getInstance().getReference("Product_Variation")
val updates = hashMapOf<String, Any?>()
for (i in removedProductVariationIdList){
   updates.put("/$i", null)

Firebase Structure - It will delete all the key (e.g. 3, 4, 5, 8) stored in removedProductVariationIdList together with its children, whole branch dissapears, which is exactly what i want :

Rent Charter Buses Company
Image data not saving to MongoDB

Image data not saving to MongoDB

Preface: using Nodejs w/Express to build a blog website and using multer to upload an image to mongoDB

Is it possible to make MYSQL table to be read only(cannot modify the details)

Is it possible to make MYSQL table to be read only(cannot modify the details)

Hello may I ask if it is possible to make a MYSQL table to read only? In which I had a table for student records which is to be updated whenever a user/student registers which saves details from the MYSQL database which is non-modifiable due to being read onlyIf...

svg logo not fully displayed in firefox

svg logo not fully displayed in firefox

so this is my svg logo rendered in chrome:

Laravel 8 route

Laravel 8 route

I run php artisan route:cache ,I didn't notice that this command can only run in production and cause this error when I want to run php artisan route:list