Skip to content

Instantly share code, notes, and snippets.

@jofftiquez
Forked from katowulf/firebase_copy.js
Last active April 7, 2024 13:29
Show Gist options
  • Save jofftiquez/f60dc81b39d77cd4eb1f5b5cbe6585ad to your computer and use it in GitHub Desktop.
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?
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();
});
});
}
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();
});
})
}
@xpratov
Copy link

xpratov commented Apr 7, 2024

Hello, how do you do? 💎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment