Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set value of a child in Firebase

I have a firebase database having a child - "hello" having value - "one". Now, using the javascript, I need to set the value of "hello" as "two". Thanks in advance. Please help.

like image 879
Hello World Avatar asked Mar 10 '23 03:03

Hello World


1 Answers

This is a really basic question. The answer can be easily found in the firebase docs. I'd strongly recommend you to always keep an eye on the docs when learning how to use firebase, because it is a great source and it covers a lot of use cases.

First, initialize your app

var config = {
      apiKey: '<your-api-key>',
      authDomain: '<your-auth-domain>',
      databaseURL: '<your-database-url>',
      storageBucket: '<your-storage-bucket>'
};
firebase.initializeApp(config);

Then, in your javascript, make sure you have a valid reference to your database and then run either one of these lines

firebase.database().ref("hello").set('two');

or

firebase.database().ref().update({hello: 'two'});
like image 182
Luis Fernando Alves Avatar answered Mar 19 '23 06:03

Luis Fernando Alves