Reputation: 115
I am going to develop android mobile app and going to use Firebase as backend. I am new to NoSql Firestore.
In my app an user has many Topics. A Topic has many posts and the post has many comments & one image. Also user has many followers.
In this scenario, how can I design Firestore database for my requirement and what is the best practice? How to reduce no.of read ?
Is following structure OK for my requirement?
Firestore-root
|
--- Topic (collections)
| |
| --- topicId (document)
| |
| --- topicId: "345"
| |
| --- title: "Topic Title"
| |
| --- viewCount: 20
| |
| --- likeCount: 30
| |
| --- Posts (colletion)
| | |
| | --- postId
| | |
| | ---postId: "321"
| | |
| | ---Title: "My title"
| | |
| | --- Image: ' '
| | |
| | --- commentsCount: 1
| | |
| | --- comments (colletion)
| | |
| | --- commentId
| | |
| | ---commentId: "123"
| | |
| | ---comment: "My Comment"
| | |
| --- likes (colletion)
| | |
| | --- likeId (document)
| | |
| | --- userId: true
| |
|
|
--- Users (collections)
| |
| --- userId (document)
| |
| --- userId: "345"
| |
| --- name: "Test Name"
| |
| --- followersCount: 20
| |
| --- followingCount: 30
Upvotes: 7
Views: 8846
Reputation: 138834
As a short an answer, yes, looks good to me for your particular requirements. I already answered a question earlier today, which is almost as yours and which I have provided a similar database schema as you already have. But you need to know that there is no perfect solution for structuring a Cloud Firestore database. The best solution, is the solution that fits your needs and makes your job easier. But regarding this structure, I see that you can easely query to get all necessary data, so in my opinion, go ahead with that.
Upvotes: 7