blablabla
blablabla

Reputation: 223

Firebase: Update key?

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

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

Upvotes: 18

Views: 12850

Answers (2)

Frank van Puffelen
Frank van Puffelen

Reputation: 598765

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();
});

Upvotes: 29

naouni
naouni

Reputation: 7

If it concerns debugging purpose, it can easily be done through the firebase realtime database console.

  1. Export the JSON file of your database by clicking on the settings icon and then on "Export JSON".

  2. Open it in a simple text editor, apply the required modifications and save it.

  3. In the realtime database console click on the same settings icon and then click on "Import JSON".

CAVEAT: Importing a JSON file overwrites the whole database.

Upvotes: -2

Related Questions