为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 Firestore 中组织相关的时态和固定数据?

如何在 Firestore 中组织相关的时态和固定数据?

ITMISS 2022-09-01 17:30:48
我不知道如何在Firestore中实现这种数据结构。我有这个结构:Firestore-root   |   --- liturgia (collection)   |     |   |     --- lh (documents)   |          |   |          --- oficio (collection)   |                |   |                --- 03070101 (documents)   |                        |   |                        --- himno: "Today himno for today oficio"   |                        |   |                        --- read: "Today read for today oficio"   |   |                --- 03070102 (documents)   |                        |   |                        --- himno: "Today himno for today oficio"   |                        |   |                        --- read: "Today read for today oficio"   |   |                --- 09070325 (documents)   |                        |   |                        --- himno: "Today himno for today oficio"   |                        |   |                        --- read: "Today read for today oficio"   |   |          --- laudes (collection)   |                |   |                --- 03070101 (documents)   |                        |   |                        --- himno: "Today himno for today laudes"   |                        |   |                        --- read: "Today read for today laudes"在具有固定内容的文档中,此内容永远不会更改,我需要根据日期使用该内容。oficiolaudes例如:我有任何日期,在这个日期,需要一个完整的内容。例如,当我需要显示(或)的今天内容时:oficiolaudes因为我将需要的内容2019-03-2509070325因为我将需要的内容2019-03-2603070102...因为我将需要的内容2020-03-2509070325因为我将需要的内容2020-03-2603070103...因为我将需要的内容2021-03-2503070101我想到了一个结构,根据日期将固定内容联系起来,但我不知道该怎么做。在我的应用程序中,将采用当前日期,并且基于此数据,必须找到 的固定内容 , for 等。oficiolaudes例如,in 和 in 是需要的内容,但 in 是需要的内容:2019-03-252020-03-25090703252021-03-2503070101
查看完整描述

1 回答

?
汪汪一只猫

TA贡献1898条经验 获得超8个赞

我能想到的最简单的解决方案是为每个文档使用String类型的属性,并稍微简化结构。因此,一个可能的结构可能是:date

Firestore-root
   |
   --- liturgia (collection)
         |
         --- 03070101 (document)
              |
              --- himno: "Today himno for today oficio"
              |
              --- read: "Today read for today oficio"
              |
              --- date: "20190325"
              |
              --- length: "1h"

若要获取今天的文档,只需使用以下查询:

FirebaseFirestore rootRef = FirebaseFirestore.getInstance();CollectionReference liturgiaRef = rootRef.collection("liturgia");Query query = liturgiaRef.whereEqualTo("date", today);

其中今天是.就是这样!20190325

编辑:

根据您的注释,与其将数据存储为存储,不如仅将其存储为 .这意味着无论年份如何,您都可以根据月份和日期进行查询。在本例中,今天只是 。这样,它将适用于每一年。date: "20190325"date: "0325"0325

编辑2:

根据OP的评论,我们同意一个可能的解决方案是创建一个与日期和内容相关的日历节点。


查看完整回答
反对 回复 2022-09-01
  • 1 回答
  • 0 关注
  • 81 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号