-
-
Save jofftiquez/f60dc81b39d77cd4eb1f5b5cbe6585ad to your computer and use it in GitHub Desktop.
Firebase realtime database - how to copy or move data to a new path?
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) { | |
return Promise((resolve, reject) => { | |
oldRef.once('value').then(snap => { | |
return newRef.set(snap.val()); | |
}).then(() => { | |
console.log('Done!'); | |
resolve(); | |
}).catch(err => { | |
console.log(err.message); | |
reject(); | |
}); | |
}); | |
} |
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) { | |
return Promise((resolve, reject) => { | |
oldRef.once('value').then(snap => { | |
return newRef.set(snap.val()); | |
}).then(() => { | |
return oldRef.set(null); | |
}).then(() => { | |
console.log('Done!'); | |
resolve(); | |
}).catch(err => { | |
console.log(err.message); | |
reject(); | |
}); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, how do you do? 💎