Skip to content

Instantly share code, notes, and snippets.

@katowulf
Last active July 29, 2022 15:58
Show Gist options
  • Star 48 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save katowulf/6099042 to your computer and use it in GitHub Desktop.
Save katowulf/6099042 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.value(), function(error) {
if( error && typeof(console) !== 'undefined' && console.error ) { console.error(error); }
});
});
}
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); }
});
});
}
@jofftiquez
Copy link

@gigocabrera
Copy link

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