【问题标题】:Add new item to Realtime Database array将新项目添加到实时数据库数组
【发布时间】:2021-03-09 00:23:33
【问题描述】:

我怎样才能将一个元素附加到这样的数组中?。

【问题讨论】:

    标签: node.js firebase-realtime-database firebase-admin


    【解决方案1】:

    向这样的数组结构中添加项目需要三个步骤:

    1. 读取现有数据。
    2. 确定新项目的密钥。
    3. 编写新项目。

    在代码中类似于:

    const ref = admin.database().ref("javascript");
    ref.once("value").then((snapshot) => {
      let numChildren = parseInt(snapshot.numChildren());
      ref.child(""+(numChildren+1)).set(4);
    });
    

    请注意,当涉及到 Firebase 时,这种类型的数据结构相当不习惯,我建议阅读:

    【讨论】:

    • 我是这么认为的。谢谢。
    猜你喜欢
    • 2016-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    • 2021-07-18
    相关资源
    最近更新 更多