在Firebase中存储空数组 [英] Storing empty arrays in firebase

查看:81
本文介绍了在Firebase中存储空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的firebase应用程序与React一起工作,借此我注册用户,然后将那里的信息记录到数据库中.我正在创建一个约会应用程序",我想以某种方式存储空数组.例如, matchers:[]

I have my firebase app working with React whereby I sign users up and then log there information to the database. I am creating a "dating app" and I would like some way to store empty arrays. e.g, matchers: [] etc

我尝试过这样的事情:

firebase.database().ref('users/' + userId).set({
      id: userId,
      username: name,
      email: email,
      matchers: [],
      likedUsers: [],
      disLikedUsers: []
    });

,但随后了解到,firebase并不能真正处理数组,因此现在不确定如何执行此操作.我想要一个空数组,以便当用户开始使用应用程序时,他们可以将其添加到其各种数组中.

but then read that firebase doesn't really handle arrays as such and now am not sure how to do this. I want the empty array so then when the user starts using the app they can add to their various arrays.

有什么想法吗?

推荐答案

Firebase始终建议不要使用数组.除了重新说明原因之外,我将带您指向博客文章最佳做法:Firebase中的数组.

Firebase has always recommended against using arrays. Instead of re-iterating the reasons, I'll point you to the blog post Best Practices: Arrays in Firebase.

但是您更大的问题似乎是具有 empty 数组:.如果属性没有值,则Firebase数据库不会存储该属性.这意味着空数组不会存储在数据库中,因此不会回读.

But your bigger problem seems to be having empty arrays: the . If a property doesn't have a value, the Firebase Database doesn't store that property. That means that an empty array is not stored in the database and thus not read back.

读回数据后,您必须自己重新创建这些属性.如果您对此有疑问,请更新您的问题以显示如何读取数据.

You'll have to re-create those properties yourself after you read the data back. If you're having problems with this, update your question to show how you read the data.

这篇关于在Firebase中存储空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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