Skip to content

Instantly share code, notes, and snippets.

@niekoost
Forked from jofftiquez/firebase_copy.js
Last active August 19, 2017 18:27
Show Gist options
  • Select an option

  • Save niekoost/b9b88723751aa10b6edd612ad5cbd95a to your computer and use it in GitHub Desktop.

Select an option

Save niekoost/b9b88723751aa10b6edd612ad5cbd95a to your computer and use it in GitHub Desktop.
Move or copy a Firebase path to a new location - Promise
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();
});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment