Reputation: 188
I want to Design an application with MongoDB and NODE. Before Starting I want to ask your opinion about the Database Design.
To have a familiar Example, lets Say this App is like Instagram in which data is categorized in special News Groups like Sport Art Business and Politics.
In this app Users can Upload Pictures which has comments and each Picture should be in an Special News Groups as I mentioned before.
I want to Design my Database as follows. Please tell me your ideas and suggestions.
User: [ Username, Email, Password ]
// Schema for SignUp //
UserData: [ Username, NewsGroup:[ Sport, Politics ], NewsReputation ]
// Schema for Username Home Page which shows each NewsGroup of user in a tab //
News: [ Username, NewsGroupID, Picture:[ Up to 5 ], Description, Video:[Only 1] ]
Comment: [ Username, NewsGroupID, NewsID, Comment: [1 for Each array], Commentor-Username]
Following: [ Username, Following-Username ]
Follower: [ Username, Follower-Username ]
Or I can nest Each News Array as a sub-document inside NewsGroup in UserData Schema
And nest Comment Schema inside News Schema as well.
I am new to User-Based Websites, So I will appreciate any idea and suggestion.
Thanks!
Upvotes: 0
Views: 112
Reputation: 4203
Q1: there's no 'best' pattern. which pattern is better depends on how you are going to use it. for generally ideas you can refer to the official document about data model design. however it's never that simple.
in your example, your way to store the data is OK but with some limitations. for example most of the time you display news with comments. then if you store comments inside news document, you can get them within one query, otherwise you'll have to do it in another query.
Same thing would happen to news group but you probably will not store them within news. because it's variable. and when it changes you may have to change all the group name in all news, which would be painful.
All I'm saying is, pattern serves your business. choose the most convenient pattern for your business.
Q2: I would say SQL works here, but this is also a typical scenario to use MongoDB for its high performance and high availability. you would want to know more about replication and it's auto failover features.
Q3: MongoDB comes with full text index feature after 2.6 (included). not all languages are supported, you may want to check the document first. I suggest you can make use this feature before your business goes big enough. then you can consider elastic search, lucece or other solutions.
Upvotes: 1