Google Firestore - 构建深度嵌套的有序数据 [英] Google Firestore - structuring deeply nested ordered data

查看:145
本文介绍了Google Firestore - 构建深度嵌套的有序数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何为云锻炼应用程序构建我的数据。数据模型如下:


  • 这个应用程序有很多练习套件

  • 练习有一个有序的练习列表

  • 每个练习都有一个有序的练习部分列表

  • 每个练习部分都有一个有序的列表说明
  • >
  • 每条指令都有几个属性(例如text,imageUrl等)


    我的第一个想法是将数据存储在带有编号键的后续子集合中。但是,我需要能够查询一组练习(包括所有练习,部分和说明)中的所有数据。由于子集合不包含在文档查询的结果中,因此将所有数据存储为后续子集合将需要我进行许多查询来检索单个练习集的所有数据。

    我也可以将上述每一个存储为一个单独的顶级集合,并保留对每个父类型的引用(例如,一个指令将有一个setId,exerciseId和partId)。然后,我可以对每个练习,部分和指令进行查询,并在setId上进行过滤。然而,这仍然需要多个查询,并且还需要在每个级别上进行映射来重新构建客户端上的数据。

    最后,由于我不预期需要查询过去的练习级别,我可以将所有部分和指令存储在嵌套对象/数组中的练习文档中。这对我来说有点味道,再加上当我试图通过Web控制台以这种方式添加几层嵌套数据时,firestore抛出了一个错误。

    任何指导将不胜感激。

    解决方案

    我正在寻找这个自己的答案...而不能检索整个嵌套数据的层次结构默认情况下,比实时数据库更强大的控制能力,不能拉超过1级的深度似乎对大多数真实世界的场景来说都是有问题的......

    I'm trying to figure out how to structure my data for my exercise app with Cloud Firestore. The data model is as follows:

    • The app has many sets of exercises
    • Each set of exercises has an ordered list of exercises
    • Each exercises has an ordered list of exercise parts
    • Each exercise part has an ordered list of instructions
    • Each instruction has several properties (e.g. text, imageUrl, etc)

    My first thought was to simply store the data in subsequent subcollections with numbered keys. However, I need to be able to query all data from a set of exercises (including all exercises, parts, and instructions). Since subcollections are not included in the results of a document query, storing all of the data as subsequent subcollections would require me to make many queries to retrieve all the data for a single set of exercises.

    I could also store each of the above as a separate top-level collection and keep a reference to each of the parent types (e.g. an instruction would have a setId, exerciseId, and partId). I could then do a query for each of exercises, parts, and instructions, filtering on setId. However, this still requires multiple queries and also would require mapping through at each level to reconstruct the data on the client.

    Finally, since I don't anticipate a need to query past the exercise level, I could store all parts and instructions within the exercise document in nested object / arrays. This smells a bit to me, plus when I tried to add several levels of nested data in this way via the web console, firestore threw an error.

    Any guidance would be greatly appreciated.

    解决方案

    I'm looking for an answer to this myself...while being able to not retrieve the entire hierarchy of nested data by default gives us greater control than the Realtime Database, not being able to pull more than 1 level deep seems problematic for most real-world scenarios...

    这篇关于Google Firestore - 构建深度嵌套的有序数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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