Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Firestore Database Design

1amageek
August 31, 2018

Firestore Database Design

This paper will explain the relationship of Cloud Firestore.

1amageek

August 31, 2018
Tweet

More Decks by 1amageek

Other Decks in Technology

Transcript

  1. System Device Technology Ltd, 2017.5 2015.10 2009.4 2018.6 Timers Inc

    Cookpad Inc Freelance 2018.9 Stamp Inc LSI design engineer iOS developer Business development, Development Manager CEO Bio
  2. Cloud Firestore • Flexibility • Expressive querying • Realtime updates

    • Offline support • Designed to scale SubCollection is an important feature of Cloud Firestore.
  3. How to make a relationship in Cloud Firestore? • Key

    • Reference • Query • SubCollection • Same ID We need to understand Client Side Join to understand the NoSQL relationship. There are several ways to create a relationship in Cloud Firestore.
  4. Client Side Join Cloud Firestore Data Client Side Join loads

    necessary data each time. Snapshot Data
  5. Relationship by Key ID: xxx child: yyy ID: yyy parent:

    xxx Key Relationship is used for cross-referencing. However, since Document only knows the ID of the reference destination, the developer must manage the path. /parent/xxx /child/yyy
  6. Relationship by Reference ID: xxx child: yyy ID: yyy parent:

    xxx Reference Relationship is used for cross-referencing. It holds the reference path. /parent/xxx /child/yyy /child/yyy /parent/xxx
  7. Relationship by Query, SubCollection • Reference The snapshot acquired by

    the query does not contain data. • Value It contains data in the snapshot acquired by the query. There are two kinds of relationship by Query, SubCollection.
  8. Relationship by Query ID: 0 parent: yyy ID: 1 parent:

    xxx ID: 2 parent: xxx ID: 3 parent: yyy /child/ Here, the relationship between parent and child is associated by ID. firestore .collection(“child”) .where(equalTo: “xxx”)
  9. Relationship by Query ID: yyy data: { } /junction/ ID:

    0 parent: yyy child: xxx ID: xxx data: { } /parent/ /child/ This expresses relationships through junction collections.
  10. ID: xxx data: { } ID: yyy data: { }

    /parent/ /parent/child/ Relationship by SubCollection The SubCollection itself represents a relationship.
  11. ID: xxx data: { } ID: yyy data: { }

    ID: yyy /parent/ /child/ /parent/child/ Reference Relationship by SubCollection Create a relationship by having the reference ID in SubCollection.
  12. ID: xxx data: { } ID: xxx data: { }

    /parent/:same_id /child/:same_id Relationship by Same ID By using the same ID for another pass, we express the relationship between the two documents.
  13. Security Rules • It is not possible to limit individual

    fields. It is necessary to separate documents between secure information and non-secure information. • When reading limits are applied, the query cannot be used. It is necessary to use SubCollection to create a secure collection. I will explain only the necessary points here. It takes time to explain security rules in detail.
  14. Same ID It has a different structure with the same

    ID. Same ID is suitable for separating public information from private information.
  15. Field Query It is the same as `where` Query of

    RDB. Field Query is suitable for expressing relationships of published information.
  16. Duplicated Data ID: yyy data: { } /parent/item/ ID: 0

    parent: yyy child: xxx ID: xxx data: { } /parent/ /child/ Writes exactly the same data to the two references.Writes exactly the same data to the two references. By doing this, JOIN becomes unnecessary, and data can be accessed at high speed. /child/item/ ID: 0 parent: yyy child: xxx
  17. 1 : 1 1 : N N : N Key

    Reference Field Query SubCollection ( Nested Collection ) Junction Collection Reference Collection Same ID Cloud Firestore Relationships Duplicated Collection