Failed to configure trigger providers/cloud.firestore/eventTypes/document.update

爱⌒轻易说出口 提交于 2020-01-25 06:03:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!