Fireship · @fireship
Firestore Data Modeling - Five Cool Techniques
Uploaded April 18, 2019 · Length 11:44
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.
- 0:00
[Music]
- 0:05
one of the most challenging aspects of
- 0:08
building any app is determining the
- 0:09
optimal data structure ideally you want
- 0:11
to maximize performance while minimizing
- 0:13
costs but that's easier said than done
- 0:15
and especially so with a no SQL database
- 0:17
like firestore because you really have
- 0:19
to plan ahead on how you model your data
- 0:20
last week I asked everybody on our slack
- 0:22
channel to send me the biggest
- 0:24
challenges that they faced modeling data
- 0:25
and firestore and this conversation
- 0:27
snowballed into an entire new course on
- 0:29
fire ship dedicated completely to no SQL
- 0:31
data modeling and queries so this is a
- 0:33
topic you're interested in consider
- 0:35
becoming a pro member to get access to
- 0:37
that course and I'll leave a discount
- 0:38
code in the video description in today's
- 0:40
video we're going to look at five
- 0:41
different ways you can structure and
- 0:43
query your data that you may not know
- 0:44
about and each technique that we'll look
- 0:46
at is based on a real submission from
- 0:47
the community a minute ago I said that
- 0:49
you have to plan ahead when structuring
- 0:51
your data so what do I mean by that
- 0:53
exactly
- 0:53
well the basic idea is that you want to
- 0:55
pre render your data so that it fits the
- 0:57
view or the screen in your app as
- 0:58
closely as possible ideally you only
- 1:00
need to make one document read or one
- 1:02
query to a collection to fill the entire
- 1:04
view with data this differs from a
- 1:06
relational SQL database where the idea
- 1:08
is to break your data into a lot of
- 1:09
small pieces and then join it all
- 1:11
together server-side heard people say
- 1:13
that fires store or no SQL databases in
- 1:15
general are not good for relational data
- 1:17
modeling but that's actually not true
- 1:18
and it's really just a matter of
- 1:19
rethinking the way that you model data
- 1:21
in general and what you'll find is that
- 1:22
you can solve all the same problems that
- 1:24
you can with SQL but you can do it in a
- 1:26
way that's faster less expensive and
- 1:27
more flexible with that being said let's
- 1:29
go ahead and jump into our first data
- 1:30
model and access pattern this suggestion
- 1:33
comes from Samrat and he wants to query
- 1:34
a collection based on whether or not a
- 1:36
user was mentioned in a post in that
- 1:38
collection this is similar to something
- 1:40
like Twitter where if you mention a user
- 1:41
name with the @ symbol it will notify
- 1:43
that user that they've been mentioned
- 1:44
and they also might want to see a list
- 1:46
of all the tweets that they've been
- 1:47
mentioned in in this case we have a
- 1:49
many-to-many relationship where a tweet
- 1:51
can have many mentioned users and a user
- 1:53
can be mentioned in many tweets but the
- 1:55
thing to keep in mind here is that a
- 1:56
tweet or a post can maybe only have one
- 1:58
to 10 mentioned users but a user can be


