Home > Software engineering >  Good option in Firestore
Good option in Firestore

Time:04-30

I have a project about hotel booking. I am creating the database in Firestore. I have a collection "regions" -> sub collection "districts". Now I want to save list hotels. Should I save them in subcollection of districts or create other collections. I want to be good at performance.

CodePudding user response:

I would go with a new hotels collection, and then on every document in the collection copy across the regionId and districtId. Personally I never nest deeper than one subcollection, as I think it creates a messy/confusing data structure.

CodePudding user response:

General NoSQL philosophy:

  1. DO Repeat Yourself

Static or mostly static data SHOULD be repeated where convenient (such as a User's name for display, or in your case regions and districts). There should be ONE "source of truth" record for such data, but since the data is static you can add it to things like Blog Posts, Comments, etc so it's already available for display and queries. Try to have everything you need to display or find a "thing" in a single document representing that "thing".

  1. DON'T design your queries to fit your database structure

Design your database structure to fit your intended queries Think about how you want to "ask questions" from your database - and design your structure to make it easy to query your data the way you want to use it.

  • Related