【问题标题】:Cloud Functions for Firebase iterate through a child nodeCloud Functions for Firebase 遍历子节点
【发布时间】:2017-09-11 02:37:22
【问题描述】:

我刚开始使用 firebase 函数,我是 node.js 环境的新手,有人可以告诉我如何遍历子节点并获取子值。

【问题讨论】:

标签: node.js firebase google-cloud-functions


【解决方案1】:

看这个例子:

  const parentRef = admin.database().ref("path");
  return parentRef.once('value').then(snapshot => {
      const updates = {};
      snapshot.forEach(function(child) {
        updates[child.key] = null;
      });
      return parentRef.update(updates);
  });

【讨论】:

  • 此代码将简单地从我的路径中删除所有数据。那我为什么要那个?
  • 这只是一个如何遍历子节点并获取子值的示例
【解决方案2】:

你看过Cloud Functions for Firebase Samples吗?它们包含许多有用的常见操作示例。 this sample 中的代码显示了您正在寻找的一些内容。

【讨论】:

    猜你喜欢
    • 2017-10-17
    • 1970-01-01
    • 2017-09-09
    • 1970-01-01
    • 2017-09-07
    • 2018-01-03
    • 2022-12-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多