什么是更改Firebase数据结构的正确方法? [英] What is the proper way to change Firebase data structure?

查看:105
本文介绍了什么是更改Firebase数据结构的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个Firebase数据库正在工作。



突然间,我想在对象中添加一个额外的字段。
$ b


  1. 导出数据json文件然后手动添加它?

  2. >以编程方式添加它?

您对修改Firebase架构有何建议? p>干杯
那么

解决方案

正如指出这是一个广泛的问题,所以不要把我的答案作为一个确定的解决方案。这只是一些建议,人们可能不会同意所有这些(因为这不是一个伟大的StackOverflow Q / Aanswer)。

我建议下载数据库内容作为JSON,做一个副本,所以你有原来的,如果出错了,进行编辑(手动或编程),并上传新的JSON。

通过下载和上传整个JSON出现网络问题的可能性较小。



请注意,如果您拥有真实用户,这仍然很可怕,因为如果他们在您下载JSON并上传新的,更改将会丢失。



如果您承担不起这个风险,那么您可能需要解决这个事实:数据结构对新旧数据不一致。如果您的应用只使用了一些Firebase服务,那么您可能会能够在更新数据库时暂时关闭它们(例如,托管您可以部署一个页面,其中显示关闭维护并且不与Firebase交互)。

Let's say I have a Firebase database in working.

Suddenly I want to add an additional field in an object. What's the proper way to do it?

  1. Export the data json file then add it manually?
  2. Add it programmatically?

What's your suggestions for modifying the Firebase schema?

Cheers Well

解决方案

As pointed out this is a broad question, so don't take my answer as a definitive solution. It's just a few suggestions, and people may not agree on all of them (as such not a great StackOverflow Q/Aanswer).

I would suggest to download the database contents as JSON, make a copy so you have the original if it goes wrong, make edits (manually or programmatically) and upload the new JSON.

By downloading and uploading the entire JSON there is less chance that something goes wrong due to network issues.

Note that this still is scary if you have real users, because if they make changes between the time you download the JSON and upload the new one, the changes will be lost.

If you can't afford this risk, then you may have to work around the fact that the data structure isn't consistent for new and old data. I won't get into how best to handle that, as there are too many options.

If you only use a few of the Firebase services for your app, you might be able to temporarily shut them down while you update the database (e.g. for hosting you can deploy a page that says "Down for maintenance" and which doesn't interact with Firebase).

这篇关于什么是更改Firebase数据结构的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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