创建文档时触发云功能

时间:2019-04-19 15:16:03

标签: firebase google-cloud-firestore google-cloud-functions

我需要创建一个firebase云功能,该功能将在每次向集合中添加文档时触发。这个功能:

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

  });

我在控制台中遇到以下错误:

  

功能[sendEmailConfirmation(us-central1)]:部署错误。   无法配置触发器提供程序/cloud.firestore/eventTypes/document.create@firestore.googleapis.com( gcf .us-central1.sendEmailApplicationConfirmation)

在Firestore数据库中,我有一个具有多个文档的集合“ multies”,而对于每个文档,我也有一个“ tenties”集合,其中也可能有多个文档。每当我们向“ multies”集合中任何文档的“ tenties”集合中添加文档时,我的函数便会触发。

我可以在配置路径或遇到其他错误方面获得任何帮助吗?

1 个答案:

答案 0 :(得分:2)

我认为您不应在路径中重复使用通配符: 尝试使用static async Task Main(string[] args) { var timeout = TimeSpan.FromSeconds(1); var cts = new CancellationTokenSource(timeout); try { await IndirectDelay(10, cts.Token); await Task.Delay(timeout + TimeSpan.FromSeconds(1)); await IndirectDelay(10, cts.Token); } catch (OperationCanceledException ex) when (cts.IsCancellationRequested) { Console.WriteLine(ex.CancellationToken == cts.Token); // false Console.WriteLine("Our token is canceled."); } catch (OperationCanceledException) { Console.WriteLine("Canceled for some other reason."); } catch (Exception) { Console.WriteLine("General error."); } } private static async Task IndirectDelay(int timeout, CancellationToken token) { using (var internalCts = new CancellationTokenSource()) using (var cts = CancellationTokenSource.CreateLinkedTokenSource(token, internalCts.Token)) await Task.Delay(timeout, cts.Token); } 而不是'multies/{multiId}/tenties/{tentiId}'

请记住,它们将在您的context.params对象中可用。

相关问题