YellowPillow
YellowPillow

Reputation: 4270

Firebase: how to delete users from multiple nodes

Say I have a situation where my database is structured like this:

{  
   a:{  
      key1:user1_UID,
      key2:user2_UID,
      key3:user3_UID
   },
   b:{  
      key1:user1_UID,
      key2:user3_UID
   },
   c:{  
      key1:user1_UID,
      key2:user3_UID
   }
}

and I want to delete user1_UID from all the nodes a, b, c when any of the user1_UID's are deleted.

For example if I delete key1:user1_UID from node b is there a way to also delete key1:user1_UID from node a and nodec, without iterating through all the nodes? Or am I structuring my data wrongly (note that these may be more deeply nested)?

Upvotes: 0

Views: 188

Answers (1)

Nikhil Sengar
Nikhil Sengar

Reputation: 101

if you know the path to the all nodes, then you can use Update command to delete all of them, correct me if i am wrong.

var updateData = {};

updateData["a/key1"] = null;
updateData["b/key1"] = null;
updateData["c/key1"] = null;

firebase.database().ref().update(updateData, function(error)
{
  if(error)
  {
   //error goes here
  }
}  

Upvotes: 1

Related Questions