Cloud Firestore Data Modeling (Google I/O'19)
Why Stack Overflow recommends it
Stack Overflow users link it as the go-to primer on Firestore data modeling when answering questions about collection structure, denormalization, and query limits.
Recommended by 5 people across 4 different months, 2019 to 2021.
What it is
A Google I/O 2019 session by Todd Kerpelman of the Firebase team on how to structure data in Cloud Firestore. It walks through common app types and use cases, showing how to keep queries possible, fast, and cheap in a NoSQL document database.
What people said
Recommends Mangesh · 2020-06 · Stack Overflow · on “Structuring of data for users in firebase”
There are multiple ways in which this could be done, but it highly depends on your business logic that which one is right for you. One thing is for sure that, you will need to have Security Rules to control access. Off the top of my head, you could: Create two different collections for private posts and public posts. private_posts will be a sub-collection under user document and public_posts will be collection at the same level of users collection. There will be only one collection posts at the same level of users collection, but a post will have flag to denote that it is private to author only. I encourage you to watch this video [this video] to learn more about Data Modeling.
Recommends OFRBG · 2020-08 · Stack Overflow · on “Firebase: How to submit form data to different collections?”
Firestore (and other document-based databases) have techniques to achieve what you're trying to do in, relatively speaking, better ways. I would start here if you're not into technical literature: [this video]
Recommends Kunal M · 2020-08 · Stack Overflow · on “How to find documents in an x mile radius using geohashes without filtering on client?”
Firstly, hi Frank! I only got into geohashing after watching your presentation on it: [LINK] Secondly, if you watch this video from 29:50 - 30:35 [this video] Is this not the same problem I would have if I filter on the client?
Recommends Louis Coulet · 2021-01 · Stack Overflow · on “How to query documents from a sub-collection, based on a main collection's field and a sub-collection's fields in cloud firestore?”
If I understand correctly, you want to retrieve all products with a certain tag and pincode (I suppose this is similar to a postal zipcode?). There really are only two alternatives that I can think of: Collection group query As you mention, you can store both tag and pincode in product documents. Then perform a single collection group query along these lines (pardon the javascript, but I am not familiar with Dart, it should be very similar): var products = await firestore.collectionGroup('products') .where('tag', '==', 'coffee') .where('pincode', '==', '234144').get(); As you have noted, with this solution you need to keep pincode in each product This piece of data is duplicated and it is no
Recommends Mar · 2021-10 · Stack Overflow · on “How can i add new indexes to an array in an existing document in Firebase Firestore?”
yes it would increase the query cost, to get all the users in a particular team you would use reads. what option is better depends on your use case, but this is another topic, data modeling [this video] . I've also updated my answer to provide a solution to your original problem
Cites Soorya · 2020-05 · Stack Overflow · on “Using "array-contains" Query for Cloud Firestore Social Media Structure”
Also, a firestore document has a limitation of 40,000 index fields. This means if you have a document with 40,0010 fields (each and every element in an array and maps are considered as a field for indexing) the last 10 fields will not be indexed, SO you will never be able to query those data. Reference: [this video]
Cites Louis Coulet · 2021-03 · Stack Overflow · on “firebase firestore: Performing SQL-like joins”
Bearing in mind two things about Firestore: query execution time depends on the size of the result set , and not on the total number of documents we cannot do join queries (this is a consequence of the constraint on execution time) * a few solutions come to mind to handle your comments and users: Data modeling Duplicate the user info in the comments This was your first approach and it is the suggested way for dealing with such cases in NoSQL, it is coined "de-normalization". As you pointed out, it means that when a user's name or avatar changes, you have to modify all associated comments with a Cloud Function. However, as pointed out by @RobertKawecki (or is it Freddie? ), you should probabl