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

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

Suhaib Janjua
  • 3,538
  • 16
  • 59
  • 73
blablabla
  • 225
  • 1
  • 3
  • 10

2 Answers2

29

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();
});
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
-2

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.

naouni
  • 7
  • 1
  • Like said in the answer, this solution can't really be used in a production environment. The procedure is just too slow. – sampoh Mar 20 '17 at 07:34
  • @sampoh would a solution to this be to have two DBs in sync and just switch the ref if you need to update one then switch it back after changing and uploading Jason? – evu May 31 '17 at 06:57
  • @evu, you are not going to be fast enough. The problem is that there might be constant requests to Firebase on production env. When you are done importing, you may have already lost data that was modified in the master DB during the JSON edit. – sampoh Jun 01 '17 at 10:53