Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase: Update key?

Tags:

firebase

{ 
    43268jfjn7983-347983:
    {
         title: 'hello world', 
         time: '1000'
    } 
}

As above, I just want to update 43268jfjn7983-347983 to something else, is this possible in firebase?

like image 247
blablabla Avatar asked Mar 18 '15 07:03

blablabla


People also ask

How do I get my Firebase key?

Firebase automatically creates API keys for your project when you do any of the following: Create a Firebase project > Browser key auto-created. Create a Firebase Apple App > iOS key auto-created. Create a Firebase Android App > Android key auto-created.

Is Firebase key value?

In Firebase Database everything is a node, that follows the pattern key: value. Firebase Database provides us with a simple way to generate unique keys. Unique keys create new items while uploading data to a previously stored key will update.

Which method used to update the Firebase data?

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

Where is Firebase private key?

In the Firebase console, open Settings > Service Accounts. Click Generate New Private Key, then confirm by clicking Generate Key.


1 Answers

There is no way to change the key of an existing node.

So instead I'd go for:

var ref = new Firebase('https://my.firebaseio.com/');
var child = ref.child('43268jfjn7983-347983');
child.once('value', function(snapshot) {
  ref.child('somethingElse').set(snapshot.val());
  child.remove();
});
like image 74
Frank van Puffelen Avatar answered Sep 19 '22 13:09

Frank van Puffelen