Created
September 18, 2014 00:15
-
-
Save mimming/d0272f5cf3b8953b49c0 to your computer and use it in GitHub Desktop.
Rename a key in firebase across many nodes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ref = new Firebase("https://<your-firebase>.firebaseio.com/path-to-your-node"); | |
ref.on("child_added", function(snap) { | |
var data = snap.val(); | |
data.phonenumber = data.contact; | |
delete data.contact; | |
ref.child(snap.name()).set(data, function(error) { | |
if( error && typeof(console) !== 'undefined' && console.error ) { console.error(error); } | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This needs to be updated for the newer version of Firebase. For example, snap.name() has been deprecated, and I'm not too sure about that "data.phonenumber" syntax.