onUpdate angular firestore cloud functions coding example:-
Hey, guys today I teach you how to create firestore cloud function using typescript with firebase cloud database main function trigger name onUpdate trigger update data before to after with firestore cloud functions example.
exports.onUserUpdate = functions.firestore.document('users/{uid}')
.onUpdate((change, context) => {
const after = change.after.data();
const before = change.before.data();
console.log(after);
console.log(before);
return exports.afs.collection('profiles').doc(context.param.uid)
.set(after || {});
});
.onUpdate((change, context) => {
const after = change.after.data();
const before = change.before.data();
console.log(after);
console.log(before);
return exports.afs.collection('profiles').doc(context.param.uid)
.set(after || {});
});
How to write firestore from cloud function:-
make file index extension called ts and write the program who describe by me-
export const onUserUpdate = functions.firestore.document('user/{uid}')
.onUpdate((change, context) => {
const after= change.after.data();
.onUpdate((change, context) => {
const after= change.after.data();
const befoure= change.befoure.data();
return afs.collection('profiles').doc(context.params.uid).set(after || {});
});
return afs.collection('profiles').doc(context.params.uid).set(after || {});
});
deploy cloud firestore functions on the server:-
after creating the cloud functions deploy on server using this command:
'firebase deploy --only functions:onUserUpdate' and after some time these operations complete successfully.
