Skip to content

Instantly share code, notes, and snippets.

@kirtan403
Forked from katowulf/firebase_copy.js
Last active September 30, 2016 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirtan403/211743b6d0e93bd25cc032de0fb2b77e to your computer and use it in GitHub Desktop.
Save kirtan403/211743b6d0e93bd25cc032de0fb2b77e to your computer and use it in GitHub Desktop.
Move or copy a Firebase path to a new location
function copyFbRecord(oldRef, newRef) {
oldRef.once('value', function(snap) {
newRef.set( snap.val(), function(error) {
if( error && typeof(console) !== 'undefined' && console.error ) { console.error(error); }
});
});
}
function moveFbRecord(oldRef, newRef) {
oldRef.once('value', function(snap) {
newRef.set( snap.val(), function(error) {
if( !error ) { oldRef.remove(); }
else if( 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