-
-
Save jofftiquez/f60dc81b39d77cd4eb1f5b5cbe6585ad to your computer and use it in GitHub Desktop.
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(); | |
}); | |
}) | |
} |
Change:
oldRef.once('value').then(snap = {
to:
oldRef.once('value').then(snap => {
@willocdev @LucasFsc thanks! I missed that one.
Here is a typescript version for move:
async function moveFbRecord(oldRef, newRef) {
try {
var snap = await oldRef.once('value');
await newRef.set(snap.val());
await oldRef.set(null);
console.log('Done!');
}catch(err) {
console.log(err.message);
}
}
@oyakitori Nice! Thanks.
I'm looking for a Cloud Firestore version of copy and move. Any ideas?
@gigocabrera I haven't explored Firestore yet. 😅
Hello, I'm kinda new to firebase functions, I know how to deploy it and everything but how does one use this? I assume you need to call this function inside from firebase function that starts with 'exports'? I'm trying to make a function where a record or child 'A' that has a set of data to a new path and when one value inside child 'A' changes, which is to my knowledge by using ()onWrite event, but my problem are defining and the structure of the firebase function, can anyone provide me an example of such function?
@savageangelz can we see what you've already done?
Can I get a Java Implementation of this?
Hello, how do you do? 💎
Error in line 3:
"=" should be "=>"