Jose Raul Perera
Jose Raul Perera

Reputation: 878

cloud function trigger on create document

I need to create a firebase cloud function that will trigger every time I added a document to the collection. This the function:

exports.sendEmailConfirmation = functions.firestore.document('multies/{id}/tenties/{id}').onCreate((snap, context) => {
    // Get an object representing the document
    //...
    return transporter.sendMail(mailOptions).catch((err) => {
        console.error(err);
        return {
            error: err
        }
    });

  });

I'm getting the following error in the console:

functions[sendEmailConfirmation(us-central1)]: Deployment error. Failed to configure trigger providers/cloud.firestore/eventTypes/[email protected] (gcf.us-central1.sendEmailApplicationConfirmation)

In the Firestore database I have a collection 'multies' that have multiple documents and foreach document I have a 'tenties' collection that could have multiple documents too. My function should trigger every time we add a document to the 'tenties' collection in any document in the 'multies' collection.

Can I get any help on how I'm configuring the path or what other error I'm having here?

Upvotes: 0

Views: 1180

Answers (1)

MichelDelpech
MichelDelpech

Reputation: 863

I think you shouldn't have duplicated wildcards in your path: try 'multies/{multiId}/tenties/{tentiId}' instead of 'multies/{id}/tenties/{id}'

Keep in mind that they will be available in your context.params object.

Upvotes: 3

Related Questions