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

Viewed 2633

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;
                });
            });
        });
    });
6 Answers

Check the de function trigger have a typo.

functions.firestore.document('users/{user_id')

This should be:

functions.firestore.document('users/{user_id}')

Check the function trigger have a typo.

functions.firestore.document('users/{doc-id}')

This should be:

functions.firestore.document('users/{id}')

Hyphens do not allow the functions deploy properly

Future readers

Also make sure you're not using $ character with your wildcard (which I accidentally did).

functions.firestore.document('users/${user_id}')

(Notice the $ sign which should not be present)

This should be:

functions.firestore.document('users/{user_id}')

It's not a JS template literal

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}"

Also double check if you have any authentication (email, anonymous, google, whatever) activated as it will give the same error if you have nothing activated yet.

For Readers, Also keep in mind the path to the documents for example

/users/{id}/employee/{id}

can not have the same path variable name, instead change it to something else like /users/{userId}/employee/{employeeId}. Fixed my issue with deploying firebase functions

Related