问题
I plan on updating the news_author_user_type every time an update happens on user_type in users node
Here's my code
exports.onUpdateUserType = functions.firestore
.document('users/{user_id')
.onUpdate((change, context) => {
const newUserDoc = change.after.data();
const user_type = newUserDoc.user_type;
const user_id = context.auth.uid;
const db = admin.firestore();
const newsRef = db.collection('news').where('news_author_id', '==', user_id);
const news = newsRef.get().then(onSnapshot => {
onSnapshot.forEach(result => {
const news_id = result.id;
const newsDoc = db.doc(`news/${news_id}`);
const news_author_type = {
news_author_type:user_type
};
newsDoc.update(news_author_type).then(onUpdate => {
return onUpdate;
}).catch(onErrorUpdate => {
return onErrorUpdate;
});
});
});
});
回答1:
Check the de function trigger have a typo.
functions.firestore.document('users/{user_id')
This should be:
functions.firestore.document('users/{user_id}')
回答2:
exports.achievements = functions.firestore.document("notifications/{any}/{any}/{any}").onCreate((snap, context) => {
In my case i changed "notifications/{any}/{any}/{any}" to: "notifications/{anyday}/{anytype}/{anydoc}"
来源:https://stackoverflow.com/questions/52447445/failed-to-configure-trigger-providers-cloud-firestore-eventtypes-document-update