将数组添加到查询中的所有节点-Firebase JS [英] Add array to all nodes in query - Firebase JS

查看:58
本文介绍了将数组添加到查询中的所有节点-Firebase JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了这样的结构:

{'-LH88EMN8Q0Mh5ZxbXyx':{
  u_id: 101,
  g_id: 6064,
  members:[101, 102]
  last_msg:'testing'
},
 '-eyJ0eXAiOiJKV1QiLC':{
  u_id: 102,
  g_id: 6065,
  members:[101, 102],
  last_msg:'testing'
},
etc
}

我正在使用查询来恢复每个具有组ID的商品;但是我需要在查询的每个交互中添加具有当前user_id的数组.像这样:

I´m using a query to recover every item with group id; but i need to add to every interaction in query an array with de current user_id. Something like:

firebase.database().ref('msgs').orderByChild('g_id').equalTo(gID) .update({ dBy: [user_id] });

firebase.database().ref('msgs').orderByChild('g_id').equalTo(gID) .update({ dBy: [user_id] });

但不能识别该功能;还是什么也没发生.

But not recognice that function; or nothing happen.

推荐答案

Firebase Realtime Database仅在知道要写入的确切位置时才可以写入数据.它不支持您可能通过SQL知道的诸如更新查询之类的东西.

Firebase Realtime Database can only write data if it knows the exact location to write to. It doesn't support something like update queries that you may know from SQL.

这意味着您需要将侦听器附加到查询,并从那里更新每个单独的结果.

This means that you'll need to attach a listener to the query, and update each individual result from there.

它看起来像这样:

firebase.database().ref('msgs').orderByChild('g_id').equalTo(gID)
    once("value", function(snapshot) {
        snapshot.forEach(function(child) {
            child.ref.update({ dBy: [user_id] });
        });
    });

这篇关于将数组添加到查询中的所有节点-Firebase JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆