Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase How to update multiple children?

I have parent with many children like this:

 Parent:{
        "childe1":"data",
        "childe2":"data",
        "childe3":"data",
        "childe4":"data",
        "childe5":"data"
 }

How can I update the children [ childe1 , childe2 , childe3 ] at same time, preventing any other user from updating them at same time?

like image 968
Amr Ibrahim Avatar asked Nov 30 '16 01:11

Amr Ibrahim


People also ask

Can firebase handle 10 million users?

The limit you're referring to is the limit for the number of concurrently connected users to Firebase Realtime Database on the free Spark plan. Once you upgrade to a payment plan, your project will allow 200,000 simultaneously connected users.

Which method is used to update firebase data?

For updating a single node in our JSON database, we simply use setValue() on the correct child reference.

How do I create a multiple realtime database in firebase?

Create multiple Realtime Database instances In the Firebase console, go to the Data tab in the Develop > Database section. Select Create new database from the menu in the Realtime Database section. Customize your Database reference and Security rules, then click Got it.


1 Answers

To update multiple properties at the same time, you can run an update() call:

ref.child("Parent").update({
  childe1: "newdata",
  childe2: "newdata",
  childe3: "newdata"
});

You can even specify paths as the keys, in case the properties are at different levels in the tree. Even though that doesn't seem to be the case here, the syntax would be:

ref.update({
  "Parent/childe1": "newdata",
  "Parent/childe2": "newdata",
  "Parent/childe3": "newdata"
});

The exact validation depends a bit on what you'd like to allow, but in general you'd write .validate rules on the server that validate that newData meet your requirements.

like image 58
Frank van Puffelen Avatar answered Oct 13 '22 18:10

Frank van Puffelen