【问题标题】:Firebase Function onCreate does not workFirebase 函数 onCreate 不起作用
【发布时间】:2018-04-18 19:14:58
【问题描述】:

我想在我的 firebase 数据库中创建新订单时发送电子邮件,但创建订单时没有任何反应。我的功能:

    exports.sendEmailConfirmation = functions.database.ref('/orders').onCreate(event => { 

  const mailOptions = {
    from: '"Someone." <noreply@firebase.com>',
    to: 'someone@gmail.com',
  };

  // Building Email message.
  mailOptions.subject = 'New order from mobile app!';
  mailOptions.text = 'John Doe lorem ipsum';

  return mailTransport.sendMail(mailOptions)
    .then(() => console.log('¡¡¡ Enail sent !!!'))
    .catch((error) => console.error('Error!!', error));
});

这段代码使用 onWrite()....

【问题讨论】:

    标签: firebase google-cloud-functions


    【解决方案1】:

    您的函数未触发,因为/orders 已存在。 onCreate 触发器只会在您指定的路径是新创建的时候运行。

    如果您想知道/orders下何时新添加了一个孩子,您应该在路径中使用通配符:

    functions.database.ref('/orders/{orderId}')
    

    【讨论】:

    • orderId 必须存在于我的数据库中?
    • 刚刚遇到这个。 orderId 是 Dough 所指的wid card。当你在订单中创建订单时,这个函数会触发,orderId会保存新创建的订单的id。
    • 这里的实际名称“orderId”是虚构的,或者至少不是指特定的术语?
    猜你喜欢
    • 2019-12-19
    • 2021-12-17
    • 2020-01-19
    • 2018-05-04
    • 1970-01-01
    • 2020-06-12
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多