Тёмный
No video :(

How to Structure Your Data | Get to know Cloud Firestore #5 

Firebase
Подписаться 383 тыс.
Просмотров 302 тыс.
50% 1

It's important to get your Cloud Firestore data structure in order. Knowing when to use Maps, Arrays and Subcollections can get a little tricky. In the last episode of Get to Know Cloud Firestore, we focused mainly on theory. But now, we’re going to put that into practice and show you how you can structure your Cloud Firestore data the right way for your app. Let us know what you think in the comments below, and stay tuned for the next episode which focuses on security rules!
Choose a data structure doc → bit.ly/2NMAkDW
Watch Pt.1 of Maps, Arrays and Subcollections → bit.ly/2RZ7bsr
More episodes on Cloud Firestore → goo.gle/Cloud-...
Subscribe to Firebase → goo.gle/Firebase

Опубликовано:

 

21 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 173   
@9642arvind
@9642arvind 4 года назад
Hi Todd from 2020. You might want to add that we can now search for multiple attributes in an array using the 'array contains any' query! Great videos!
@pagevpetty
@pagevpetty 2 года назад
YES! This is exactly what I need! Thank you for sharing @Arvind Shekar. @Firebase Todd 2022, please update and with lists of pros & cons. Thanks :) if you even read these comments... I notice no replies.
@AmeliorScout
@AmeliorScout Год назад
@@pagevpetty Page.. haven't I seen you in the Academind comments section? :D!
@pagevpetty
@pagevpetty Год назад
@@AmeliorScout Probably... from a while ago.
@s3nsist4r
@s3nsist4r 5 лет назад
Love this kind of tutorial. No code, just explaining concepts of how to structure data. Looking forward to the security rules video.
@pagevpetty
@pagevpetty 2 года назад
With visuals :) Visual examples (note squares) work!
@davebeazer4007
@davebeazer4007 4 года назад
Love how you're keeping these videos current. Well done 2019 Todd
@SigmundJaehn
@SigmundJaehn 3 года назад
But where’s 2021 Todd? Is he ok and are there no updates?
@lukegordon4734
@lukegordon4734 2 года назад
This is one of the best technical talks I've seen. Super clean, super simple to follow, and really explains the trade offs. Thanks for making Firebase best practices/structure easy to understand!
@pagevpetty
@pagevpetty 2 года назад
It would also be nice to see bullet lists of pros and cons for each.
@dashandblast
@dashandblast 5 лет назад
This series is the best. These last two videos in particular have been especially helpful, addressing questions I've been thinking about for months. I look forward to the next installment.
@PeterFurstenberg
@PeterFurstenberg 5 лет назад
Trying to make sense of the firebase universe, this has been a massively informative series so far in understanding how it all works! So Thank you. PLEASE update the series with understanding permissions soon!
@eyezonmy6
@eyezonmy6 7 месяцев назад
big fan of the teaching style, going over things more than once
@theanimalix5877
@theanimalix5877 4 года назад
Well done Todd 2018 and 2019, love your vids. Can't wait for Todd 2020! :)
@mfarnham
@mfarnham 2 года назад
These videos are honestly such a treasure. They're fun, informative and easy to understand. There's a huge problem with the captions once Todd from 2019 appears. Not cool for people who need the captions. Still, 7.9/10, would recommend.
@garypiong3752
@garypiong3752 5 лет назад
Please make more videos on this series; they're all so useful!
@RayDaly
@RayDaly 5 лет назад
Hope you do How to Structure Your Data Part 2. This one is great. I'd like to see coverage of using local storage IndexedDB etc with Firestore, Performance and displaying results, very large versus very small query results. Data Structure is such a critical part of app development.
@jesselima_dev
@jesselima_dev 5 лет назад
Very nice video! Important concepts about how and when to apply which data modelling approach. I totally agree that we as developers need to know what data will be used in the application and how it's gonna be used. Also what kind of queries are inside the gather requirements for the app. Once you know what data you will need to retrieve and how often you will do it, then it will more clear about what model to use.
@joemac84
@joemac84 3 года назад
Very informative video and thanks for keeping the content up-to-date. Love the discussion around best practices too because these things can be hard to find!
@Firebase
@Firebase 3 года назад
Our pleasure!
@rammalvarez2664
@rammalvarez2664 5 лет назад
My advice for Firestore data structure: Use both, remember if you have a hammer not everything becomes nails (this phrase it's better in spanish XD). But an interesting point to notice it's implementation and mantainance time, with top level collections tends to be easier and faster for me, specially if you reuse components in Angular. Edit: This becomed more useful when Firebase introduced 'array-contains' queries
@cesmejia9014
@cesmejia9014 5 лет назад
do you mean use both subcollections and top level collections?
@cyberguygame9096
@cyberguygame9096 2 года назад
Boy... hard to understand. Why dont you just show the database how it would look in Firebase?
@adamryason5509
@adamryason5509 3 месяца назад
One thing I'm still trying to figure out is best practice for displaying the collection of "restaurants" that a user can browse. Let's say there are 20 restaurants, first option would be to query this collection every time the user browses (20 queries per browse) while a second option would be to query a document containing the list of restaurants and then just query the restaurants that they select (1 query for the list, then 1-5 queries for the restaurants). I would love to hear other's opinions!
@u2blr
@u2blr 5 лет назад
This tutorial is so good, even you are not using firebase still a good video about how to structuring data and designing system
@OmerVexler
@OmerVexler 3 года назад
Thank you Google! So elegant, Firebase is just awesome tbh.
@aaronhong4345
@aaronhong4345 4 года назад
Love the crash course vibes
@tonyalbanese6446
@tonyalbanese6446 5 лет назад
Thank you for this video. I am new to development and often doubt how I want to do things. Watching this reminds me that that there is often no one best way to do things.
@moomoomamoo
@moomoomamoo 5 лет назад
The example at 13:23, when we get the Favorite Restaurants, would it be a bad idea to use composite ids of the User and Restaurant documents for my FavoriteRestaurant documents? Assuming I have more Users than Restaurants, I would use something like ${user-id}_${restaurant-id} for my FavoriteRestaurant id. Assuming my Users and Restaurants use Firestore generated ids, my FavoriteRestaurant documents would be somewhat lexicographically close as there would be clumps of FavoriteRestaurant documents with a common beginning to their ids. How likely will this structure be at risk of hotspots? Also to give a use case for why these predeterminable ids would be useful is handling transactions over my FavoriteRestaurant documents for something like "store credit". What would be your advice on using composite ids and trying to handle this use case?
@ivanpambudi6913
@ivanpambudi6913 4 года назад
umm current day Todd, you're good to keep this up-to-date but you forget to update the subtitle too, not a big deal but sometimes it help me to better understanding
@zoulkifiroubarizi8213
@zoulkifiroubarizi8213 4 года назад
I realy love your turorials. Thanks too much.
@goleary
@goleary 5 лет назад
Am I the only one who has mis-aligned captions & subscribe / watch more content at the end of the video. I'm guessing it's due to the "Todd from 2019" segment being added after the fact. It's like this in many of the videos in this series.
@burrfect_espresso
@burrfect_espresso Год назад
Great video, so helpful in getting acquainted with structuring data in firestore. Question about your final example on using a top level collection of favorites. What are the upsides/drawbacks of tweaking your stucture by replacing the userid field on each top level favorite with an array of all the userids that favorites that restaurant (so each favorites restaurant appears in only 1 document with an array of users who have favorited it contained within?)
@remib.8524
@remib.8524 4 года назад
This is a great series of videos! Clear, fun and very informative. Thanks!
@martinmori9848
@martinmori9848 5 лет назад
Thanks for this tutorials, the real life examples are great and helps to understand everything in a simple way
@sarensmith
@sarensmith Год назад
♥️♥️
@YousefKabbara
@YousefKabbara 5 лет назад
#askfirebase Thank you for this great series, I have a model like the following: Collection: Place String name String description Int numberOfVisits and so on Q1: for the first two parameters ‘ *name and description* ’ I need to make it *multilingual* what is the best structure to make it so while keeping minimal data downloaded and the minimal number of queries? Q2: you're talking about having a sub-collection for reviews, but what about having a third collection for the relation between users-resturants-reviews ? Best, Yusuf
@ptrchovan
@ptrchovan 5 лет назад
Denormalisation is against every rule I have learned in most db specially sql. I understand this is nosql so I have no other option then get used to it which I guess will be the hardest part at structuring db in firestore. What a mess.. :o
@thelonearchitect
@thelonearchitect 4 года назад
It's a trade of read-performance against maintainability. Firestore acts more like a fast cache than a real database imo
@jasontissera4331
@jasontissera4331 Год назад
Love that there's no limit to the number of documents you can have.
@rabiahamouda8747
@rabiahamouda8747 5 лет назад
Thanks for this amazing video and for the whole series! it helped me a lot, looking forward to the next video about security rules.
@amrmonzir
@amrmonzir 3 года назад
Yes yes agreed XD
@mayankkataria7080
@mayankkataria7080 3 года назад
Should my single document contain only one chat message or an array of all chat messages ?
@trod-123
@trod-123 5 лет назад
I like the top level collections solution brought up at the end. That said, if I am understanding this correctly, by introducing denormalized data and using cloud functions to update all copies of that data when the original data changes, this means more data write operations that we'll be charged - one write per copy. Right?
@BauldyBoys
@BauldyBoys Год назад
Always glad to see Todd from 2019.
@divertechnology
@divertechnology 2 года назад
denormalized is the best. memory save is from times where memory was hard to have
@fatemebahrami7309
@fatemebahrami7309 4 месяца назад
love this tutorial! besides that, just wanted to let you know that the captions are not synced due to Todd 2019 intteruptions 😆
@glrbrasil
@glrbrasil Год назад
This is so insightful Todd, thank you 🙏
@WolfRapMotivacional
@WolfRapMotivacional 4 года назад
Firebase, React, Material UI and Typescript is awesome!
@peterhayman
@peterhayman 2 года назад
My only regret is that I have but one like to give for this video
@vincentdufour613
@vincentdufour613 4 года назад
So when you have a N-N relationship like the link "favorite" between Restaurants-Users, you create a new collection that contains the id of the restaurant, the id of the user and the favorite data. You are just normalizing the unnomalized data like one do in SQL with tables instead of collection ?
@greganderson8416
@greganderson8416 4 года назад
What if you are doing the 'inverse' of a favorite, such as a 'done' flag to filter out completed items in a task list? Why are there no inverted logic queries in firestore to support something like this? Ex: an array-not-contains query. Even based on the earlier video where it was explained that queries use a binary search on indices to produce a contiguous sequence of results I don't understand. The inverse of that is simply the concatenation of the two contiguous sequences before and after.
@nayankurude4129
@nayankurude4129 4 года назад
I am a miser when it comes to like a video.. But you are gonna get my like.. Keep the good work up.
@akikoobodo
@akikoobodo Год назад
best teacher ever!!!
@jeffodle7810
@jeffodle7810 3 года назад
Do the queries at 11:05, querying documents where a property of a map exists, still work with Firebase 8+ ? I cannot get them to work.
@lucasluizss
@lucasluizss 4 месяца назад
Great video!
@carsonskjerdal473
@carsonskjerdal473 4 года назад
This was incredibly helpful! Much appreciated, will be watching again.
@TheL96
@TheL96 5 лет назад
Thanks, Great video. bring on the much needed security rules video pls!
@haraldlons
@haraldlons 3 года назад
Great video, love it! At 08:45, I like the solution, but how can you query "get all restaurants where userID_2852 is a key in the private_data.roles map?" I feel this is a very common user case, but don't quite get how to do it. Would really appreciate your help here!
@Themusicaligera
@Themusicaligera 5 лет назад
I have a question... The example at 13:23, when we get the Favorite Restaurants, we're getting all the document, including the user_ids that have favorited that specific restaurant, what happens if a LOT of users have that restaurant as a favorite one, doesn't it exceed the indexing limit? and also isn't it useless to get all the users that have favotired that restaurant, when that field is only to query information?
@hakanbuyuktopcu3720
@hakanbuyuktopcu3720 3 года назад
I love the videos, just want to point out that the subtitles are not updated for Todd from 2019. Thanks!
@noamgonen6243
@noamgonen6243 5 лет назад
14:07 - talking to your imaginary friends eh? I thought I was the only one....
@anoopisaac
@anoopisaac 4 года назад
Hey Todd, thanks for the awesome tutorial. In my application I have list of users and all the pages that they own. There are minimal page queries that span multiple users, so following your recommendation, can I go with storing pages as a sub collection to users? just wondering whether the fact this its being 'User' object would have any impact on the structure?
@kagame6524
@kagame6524 3 года назад
Really great tutorial!
@Firebase
@Firebase 3 года назад
Thank you! Cheers!
@SandeepKumar-xu7wd
@SandeepKumar-xu7wd Год назад
at last, if we create a separate user collection and favoriteRestaurants collection. If I change the restaurant address, I have to change all documents that match the same restaurant's id in favoriteRestaurants collection. And I think it's not a good way.
@dapkman9354
@dapkman9354 5 лет назад
Great video. thank you! So much useful information and it's so interesting to watch at the same time!
@runfunmc64
@runfunmc64 5 лет назад
Very helpful, thanks so much!
@karolrvn
@karolrvn 5 лет назад
Great, broad and deep; with many considerations taken into account.
@gachugu5589
@gachugu5589 2 года назад
Last winning structure. What if another user adds the same restaurant as a favorite? Does it not mean that the user_id field will be overwritten?
@simonleichtle6913
@simonleichtle6913 5 лет назад
Now I am curious for the cloud function video :D
@kalmahiks
@kalmahiks 3 года назад
video and subtitles don't match after insert fragment from 2019(
@a1r592
@a1r592 4 года назад
Coming from SQL this feels kind of hacky but i guess it's a different way of thinking. Great video nonetheless; you explained it really well.
@varunrao2135
@varunrao2135 4 года назад
This is very very well done
@leeboyin945
@leeboyin945 4 года назад
Anyone using Firestore must watch this video before start planning data structure!
@Phoony17
@Phoony17 5 лет назад
Excelent video, right now I'm building an web app an this is extremely helpful to get your thoughts in the right direction
@oghenefokethompson7407
@oghenefokethompson7407 4 года назад
Love this kind of tutorial! greate job!
@1002CK
@1002CK 5 лет назад
Tod, can u explain about using cloud function in Cloud Firestore ? #AskFirebase
@thedevguild7525
@thedevguild7525 2 года назад
Hi the transcript and captions seems to be off! it seems to be lagging behind
@bakanndy
@bakanndy 4 года назад
"You can't run 2 array contains queries on the same array", I don't really understand why you can't except that arrays are weird. BTW thanks for the video, this is the best one on NoSQL, you're a genius.
@shamilmammadov8246
@shamilmammadov8246 4 года назад
Just perfect! Big thumb up!
@ramirauch4515
@ramirauch4515 4 года назад
all these examples are easily resolved with relational db. remind me again, why use nosql? also in the proposed solution you present separate options of use, but what if you need this and also that?
@rahistaffasia6261
@rahistaffasia6261 2 года назад
This video made me felt NoSQL has so many issues. The more I watched the more awkward I felt. This felt to me like a video on how bad NoSQL is
@RobinYoulton
@RobinYoulton 5 лет назад
Thanks Todd, this advice is right on the point for me 👍
@prasadbroo
@prasadbroo 3 года назад
I like this guy
@nadirilter3238
@nadirilter3238 4 года назад
Can we say, in this example making multiple top level storage will be more efficient than storing data as the snippets or sub-level?
@rachelnguyen9966
@rachelnguyen9966 2 года назад
Guys, @Firebase How to use reference field here? For example, I have Posts and Users collections. in Posts, reference field is Author, link to user: users/userid When get the Post details, how to get the user details from reference without using another query like: doc(db, "users", userid). I do not want to consume 2 queries for that. Suppose reference field can return the user data in get Post query too.
@luiswebdev8292
@luiswebdev8292 2 года назад
If we have a Users and a FavoritedRestaurants collection, where FavoritedRestaurants has user_id and restaurant_id, don't we end up with TONS of duplicate data? Imagine 1000 users favorite the same restaurant, then we have the same restaurant snippet in 1000 different documents. This seems like an undesirable amount data duplication. Is this a right approach to do things?
@luiswebdev8292
@luiswebdev8292 2 года назад
Okay after watching more videos I see that duplicate data is a thing in NoSQL and it's not so terrible as in SQL
@alexiszorba25
@alexiszorba25 4 года назад
What if my App/Web is multi language? How do I store a list of Types of restaurants? Should I use Remote Config and store only the Ids in Firestore? Or should I create a different structure in Firestore for that?
@elguignole
@elguignole 3 года назад
This guy know how to communicate knowledge
@josefsantamaria
@josefsantamaria 5 лет назад
Its really helpful with this kind of tutorials, why not do an updated version in firestore about event and members etc that you did for realtime database!
@Rave1502
@Rave1502 5 лет назад
Very nice video. Just adding one more use case to the given examples, please help me understand what would be the preferred approach. Now Along with user's favorite restaurants, I miraculously also receive user spending per restaurant. I want a report of individual's average spending per restaurant. And also a restaurant's per user per-month/year/etc.
@AkhilKumar-ys3ph
@AkhilKumar-ys3ph 5 лет назад
please upload all series
@AnkitMaheshwariIn
@AnkitMaheshwariIn 5 лет назад
Single query required many times to fetch collections and sub-collections together. Is there any plan in near future?
@DJNiems
@DJNiems 5 лет назад
OK so one of the rules concerning arrays was that you cannot reference elements by index. So assuming that one chooses to store favourites using the structure at 12:10, what would you do if you say, wanted to remove (i.e. "un-star") an item at the second position in your list? You cannot simply delete the item at index [1], since that is not supported. Would you instead need to instruct the database to simply replace the list with the new one constructed on the client side? Or instead, do the array operations support edit-by-value, e.g. "delete item that matches 'rest_5153'", and by virtue of real-time synchronisation, the item removed in my UI is indeed the second item, since one would assume the ordering is synchronised as well?
@afolabiaiyeloja5315
@afolabiaiyeloja5315 5 лет назад
Great video! I'm considering using GraphQL with Apollo on the client side and was wondering if it's a good method for fetching data. My stack is React | Apollo Client | Apollo Server | Firestore. Thanks for the help :)
@anaskhalil4057
@anaskhalil4057 2 года назад
good video
@eric-ampire
@eric-ampire 5 лет назад
Great video
@prabhunerahul
@prabhunerahul 3 года назад
In firestore, can we add new json object in the same document instead of creating a new document in the collection every time user adds as review? If I create separate document for each .add json object, I would have 1000 document reads per day per user which would be expensive. What would be the best optimum solution?
@danvilela
@danvilela 5 лет назад
Very good!
@3litepker
@3litepker 4 года назад
Can anyone tell me why you just wouldn't store *only* the restaurantId in the favourites array of the user collection? I'm pretty sure you could just query all the restaurantId's in the users favourites and pull all the data that way.
@MesinKasir
@MesinKasir Год назад
Subtitles is not synched after Todd from 2019 shows up
@rahulpanwar5344
@rahulpanwar5344 5 лет назад
How to trigger firebase function inside from react via onclick button
@asdfghyter
@asdfghyter 5 лет назад
The last example: Here is a problem (many-to-many-relations) that NoSQL databases are generally bad at ...[long list of possible solutions] ... the best solution is to use the traditional SQL solution of storing the many-to-many relation in a separate table.
@user-lw4zo8ip9z
@user-lw4zo8ip9z 5 лет назад
Problem with subtitles from 2:37 :(
@ahmedelsobkey2535
@ahmedelsobkey2535 3 года назад
are you find a solution for subtitles problem?
@ahmedelsobkey2535
@ahmedelsobkey2535 3 года назад
I solved the problem with selecting second choice in CC (English auto-generated)
@maindev598
@maindev598 3 года назад
thanks
@DavidChoi-wz5pn
@DavidChoi-wz5pn Год назад
Can someone explain to me how 2019 Todd appears in a video published in 2018?
@Vilmir
@Vilmir 3 года назад
Imagine this guy as a teacher in an engineering school, lucky students!
@ARITRAMUKHERJEEjan1989
@ARITRAMUKHERJEEjan1989 5 лет назад
Collection group queries Deleting a subcollection from client Regex test search in string field These 3 things and firestore will be the dream back end for all app devs :)
@rabahghiles9853
@rabahghiles9853 5 лет назад
I totally agree with you. it will become very very powerful
@admniyeokuyorsun...3044
@admniyeokuyorsun...3044 4 года назад
Yeah but then google can't earn money lolz
@camillo8575
@camillo8575 4 года назад
Really good tutorial. Isn't putting everything in top level collections like using a SQL-like database structure?
@nataoliveira2247
@nataoliveira2247 3 года назад
kinda, except you duplicate data very often
@nieldv1
@nieldv1 2 года назад
Hi, I must say I love your videos. I'm using a Firestore database and building an app that contains users and clubs, and a user can belong to multiple clubs (ie a club can have multiple users) and a user can be an admin of a club. So a club user that is an admin should be able to see and manage the users of a club, and a user can join clubs and see the details of the clubs etc. I come from a relational database background so naturally I created three top-level collections - clubs (containing club info), users (containing user info), and users_clubs, just containing the combination of clubid and userid and an isadmin indicator (eventually i will proabably want to add more roles/permissions on a user_club level). I'm wondering if in your opinion this is the best option or should I add a subcollection of clubs under users to list the clubs they belong to, or should I add clubs as a map to users (with clubid and role information)? I realize there's no one correct answer to this question but I am trying to minimize cost in terms of storage and queries. Thanks!
@zechcampbell
@zechcampbell 5 лет назад
Where can I find the video about Cloud functions you mention? Interested to see how to use Cloud functions to keep duplicate data up-to-date across multiple documents.
@BrentBroome
@BrentBroome 5 лет назад
I think that video only exists in the future (for now). Sounds like one of these on security is next, then maybe functions after that? Not sure of the team's roadmap for this series, but Todd has alluded to functions being the topic of an upcoming video a couple of times. (Someone please correct me if the functions video is already out and I've just missed it.)
@adwinang4188
@adwinang4188 2 года назад
The english CC is no longer correct after the correction from 2019
Далее