I have a cloud function that creates a Firestore entry when a new user is registered
exports.newUser = functions.auth.user().onCreate((user) => {
var userObject = {
displayName : user.displayName,
picUrl:user.photoURL,
authType:user.providerData,
email : user.email,
newUser: true,
bookings:0
};
console.log("Merge:true")
return admin.firestore().doc('users/'+user.uid).set(userObject, SetOptions.merge())
.then((response)=>{
console.log("New user result: ",response)
return response;
}).catch((err)=>
{
console.log("New user Error: "+err)
return err;
});
});
I want to use setoptions.merge() but It is not working, I want to update because I am also writing the device token on firestore for FCM messages.
NewUser ReferenceError: SetOptions is not defined at exports.newUser.functions.auth.user.onCreate (/srv/index.js:26:67) at cloudFunction (/srv/node_modules/firebase-functions/lib/cloud-functions.js:131:23) at /worker/worker.js:825:24 at at
I refered the google cloud documentation where they said to pass it as {merge:true} but that also didn't help. I refered this post on stackoverflow Why is my Cloud Firestore Transaction not merging when using SetOptions.merge()? But this also didn't work. Please help me as I don't know much about firestore cloud functions
{merge:true}
. What's wrong with that? – Doug Stevenson