简体   繁体   English

云功能已触发,但未执行

[英]Cloud Function triggered, but not executed

I have following function: 我有以下功能:

exports.onDataAdded = functions.database.ref('/Lager/Shafts/Rescue/582/582001').onWrite((change, context) => {
    if (change.before.exists()) {
            return null;
          }
          // Exit when the data is deleted.
          if (!change.after.exists()) {
            return null;
          }
          const original = change.after.val();

return change.after.ref('/Lager/Shafts/Rescue/583/583001').set(original);
});

I am trying to keep the count of product 1 equal to the count of product two (Can't put it in the same ID for several reasons). 我试图使产品1的数量等于产品2的数量(出于多种原因,不能将其放在相同的ID中)。 It executes the function and says the status is ok but does not update the new value of product 2. What am I missing? 它执行该功能并说状态正常,但不会更新产品2的新值。我缺少什么?

Please try this, Your function is exiting without executing the update. 请尝试此操作,您的函数正在退出而不执行更新。

exports.onDataAdded = functions.database.ref('/Lager/Shafts/Rescue/582/582001').onWrite((change, context) => {
    if (change.after.exists()) {
        const original = change.after.val();
        return admin.database().ref('/Lager/Shafts/Rescue/583/583001').set(original);
    }
    // Exit when the data is deleted.
    if (!change.after.exists()) {
        return null;
    }
});

This seems like a noop: 这似乎是个小问题:

exports.onDataAdded = functions.database.ref('/Lager/Shafts/Rescue/582/582001').onWrite((change, context) => {
  if (change.before.exists()) {
    return null;
  }

Or more precisely: it will only get past this code when you delete /Lager/Shafts/Rescue/582/582001 , which is not what you seem to be trying. 或更准确地说:仅当您删除/Lager/Shafts/Rescue/582/582001 ,它才会越过此代码,这似乎并不是您想要的。 My guess is that you meant the inverse in your check: 我的猜测是您的意思是支票中的倒数:

  if (!change.before.exists()) {
    return null;
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM