我应该如何构造我的firebase数据(基础 - 运动数据)?

发布于 2025-02-12 07:54:45 字数 807 浏览 0 评论 0原文

我已经使用Java创建了一个Android应用程序,并且使用了Firebase实时数据库。通过休息,我得到了JSON-DATA的城市。 “数据”的意思是:

  1. 基本数据例如城市ID,姓名或人口。他们很少改变。这在我的模型类“基础”中表示。
  2. (移动)数据每天都会改变。该课程称为“ CityData”。

基于目前是 citydata 的一部分:

public class CityData
{
    private BaseData baseData;
    private int cases;
    //...
}

目前,我只能在今天请求数据。当我将CityData-Object保存在DB中时,看起来像这样:

我的下一步:在过去的7天中保存数据。但是:Firebase也将每天保存基本数据。 我可以防止此(=>仅在不存在时保存或在发生变化时更新时保存)? 否则,我必须更改数据结构。但是哪个最好的可能性? 我的第一个想法是:创建这样的两个单独的途径:

但是,我必须从CityData中提取基于基础,并每次加入它们,例如,当我需要城市名称时,通常是。这是最好的方法吗?这是我第一次与NOSQL一起使用,所以每一个帮助都很好!

I've created an android app with Java and I use a Firebase realtime-database. Via REST, I get JSON-data for cities. "Data" means:

  1. base data like the city-id, name or population. They rarely change. This is represented in my model class "BaseData".
  2. (movement) data which changes every day. The class is called "CityData".

BaseData is currently part of the CityData:

public class CityData
{
    private BaseData baseData;
    private int cases;
    //...
}

At this time, I can only request data for today. When I save a CityData-object in my db, it looks like this:

My next step: Save the data for the last 7 days. But: Firebase would also save the base data every day. Can I prevent this (=> only save when not exists or update when something changes)? Otherwise, I have to change the data struct. But which is the best possibility?
My first idea: Create two seperate paths like this:

But then, I have to extract BaseData from CityData and join them every time, for example when I need the city name, which is often. Is this the best way? It's my first time with NoSql, so every help would be nice!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文