Fireship · @fireship

Firestore Data Modeling - Five Cool Techniques

Uploaded April 18, 2019 · Length 11:44

Firestore Data Modeling - Five Cool Techniques

Summary

Learn five cool Firestore data modeling techniques, including querying multiple tags, implementing a category system, and using composite strings for geolocation queries.

  • firestore data modeling
  • no sql database
  • data structure
  • querying multiple tags
  • category system
  • composite strings
  • geolocation queries

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    [Music]

  2. 0:05

    one of the most challenging aspects of

  3. 0:08

    building any app is determining the

  4. 0:09

    optimal data structure ideally you want

  5. 0:11

    to maximize performance while minimizing

  6. 0:13

    costs but that's easier said than done

  7. 0:15

    and especially so with a no SQL database

  8. 0:17

    like firestore because you really have

  9. 0:19

    to plan ahead on how you model your data

  10. 0:20

    last week I asked everybody on our slack

  11. 0:22

    channel to send me the biggest

  12. 0:24

    challenges that they faced modeling data

  13. 0:25

    and firestore and this conversation

  14. 0:27

    snowballed into an entire new course on

  15. 0:29

    fire ship dedicated completely to no SQL

  16. 0:31

    data modeling and queries so this is a

  17. 0:33

    topic you're interested in consider

  18. 0:35

    becoming a pro member to get access to

  19. 0:37

    that course and I'll leave a discount

  20. 0:38

    code in the video description in today's

  21. 0:40

    video we're going to look at five

  22. 0:41

    different ways you can structure and

  23. 0:43

    query your data that you may not know

  24. 0:44

    about and each technique that we'll look

  25. 0:46

    at is based on a real submission from

  26. 0:47

    the community a minute ago I said that

  27. 0:49

    you have to plan ahead when structuring

  28. 0:51

    your data so what do I mean by that

  29. 0:53

    exactly

  30. 0:53

    well the basic idea is that you want to

  31. 0:55

    pre render your data so that it fits the

  32. 0:57

    view or the screen in your app as

  33. 0:58

    closely as possible ideally you only

  34. 1:00

    need to make one document read or one

  35. 1:02

    query to a collection to fill the entire

  36. 1:04

    view with data this differs from a

  37. 1:06

    relational SQL database where the idea

  38. 1:08

    is to break your data into a lot of

  39. 1:09

    small pieces and then join it all

  40. 1:11

    together server-side heard people say

  41. 1:13

    that fires store or no SQL databases in

  42. 1:15

    general are not good for relational data

  43. 1:17

    modeling but that's actually not true

  44. 1:18

    and it's really just a matter of

  45. 1:19

    rethinking the way that you model data

  46. 1:21

    in general and what you'll find is that

  47. 1:22

    you can solve all the same problems that

  48. 1:24

    you can with SQL but you can do it in a

  49. 1:26

    way that's faster less expensive and

  50. 1:27

    more flexible with that being said let's

  51. 1:29

    go ahead and jump into our first data

  52. 1:30

    model and access pattern this suggestion

  53. 1:33

    comes from Samrat and he wants to query

  54. 1:34

    a collection based on whether or not a

  55. 1:36

    user was mentioned in a post in that

  56. 1:38

    collection this is similar to something

  57. 1:40

    like Twitter where if you mention a user

  58. 1:41

    name with the @ symbol it will notify

  59. 1:43

    that user that they've been mentioned

  60. 1:44

    and they also might want to see a list

  61. 1:46

    of all the tweets that they've been

  62. 1:47

    mentioned in in this case we have a

  63. 1:49

    many-to-many relationship where a tweet

  64. 1:51

    can have many mentioned users and a user

  65. 1:53

    can be mentioned in many tweets but the

  66. 1:55

    thing to keep in mind here is that a

  67. 1:56

    tweet or a post can maybe only have one

  68. 1:58

    to 10 mentioned users but a user can be