是否可以在不下载数据的情况下运行firebase函数onWrite,onupdate和undelete?

问题描述

export const newNodeDetected = functions.database.ref('counter/likes/{postId}').onWrite((snapshot,context) => {

    const likeCount = snapshot.after.numChildren();
    const key = snapshot.after.key;
    snapshot.after.forEach(child => {
        console.log("[--] loop",child.child('{sd}'));
    });
    console.log("[--] true or false",snapshot.after.val());
    console.log("[--] value",likeCount);
    console.log("[--] key",snapshot.after.key);
    console.log(`[--] keystring questions ${key}`);
    database.ref(`posts/${key}/likeCount`).set(likeCount).catch(console.error);
});

如果我们不包括快照,则仅具有上下文,它将仍然从该位置下载数据。

解决方法

您的功能实际上并没有“下载”任何东西。它所做的全部就是写入数据库。

传入的快照根本不是真正的“下载”。在所有情况下,该快照都将交付给您的函数。您不能告诉Cloud Functions不提供它。函数运行时它将完全存储在内存中,因此访问它将非常快。