Last active
July 29, 2022 15:58
-
-
Save katowulf/6099042 to your computer and use it in GitHub Desktop.
Move or copy a Firebase path to a new location
This file contains 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
function copyFbRecord(oldRef, newRef) { | |
oldRef.once('value', function(snap) { | |
newRef.set( snap.value(), function(error) { | |
if( error && typeof(console) !== 'undefined' && console.error ) { console.error(error); } | |
}); | |
}); | |
} |
This file contains 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
function moveFbRecord(oldRef, newRef) { | |
oldRef.once('value', function(snap) { | |
newRef.set( snap.value(), function(error) { | |
if( !error ) { oldRef.remove(); } | |
else if( typeof(console) !== 'undefined' && console.error ) { console.error(error); } | |
}); | |
}); | |
} |
I'm looking for a Cloud Firestore version of copy and move. Any ideas?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Firebase 3.x and Promise version of this.
https://gist.github.com/jofftiquez/f60dc81b39d77cd4eb1f5b5cbe6585ad