I am an experienced developer but a beginner in database management. I am wondering what is the best pattern to organize my database stored in Firestore (NoSQL).
I have two patterns in mind:
- a user has pictures. I want to be able to get all the pictures for one user, and to get the picture owner easily
- a chat room will have users, and users will have several chat rooms. It want to query a user's list of chat rooms and a chat room list of users. I want to be able to delete my chat room and its content if the last user leaves it.
What is the most efficient pattern to manage this in a Firestore context? Should I use backrefs or cross reference the documents, or should I use a query for all the images / chat rooms where the userId matches my user? How do I manage efficiently the "garbage collection" use case?
I have started with cross references but I am concerned by the extra cost of writing and editing more data (a user enters a chat room, it edits the user and the chat room), or the latency increase for the "get all pictures" use case if I store a lot of pictures and I rely only on indexes.
Aucun commentaire:
Enregistrer un commentaire