0

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.

  1. Which Approach is better?
  2. Is it better to use MongoDB or I should go with SQL Databases?
  3. If I want to have a Search-Page, What do you suggest for that?

I am new to User-Based Websites, So I will appreciate any idea and suggestion.

Thanks!

3
  • Keep in mind that there is a size limitation for each document. 16MB. Then I wouldn't save all the news into news group. But I could probably choose to save comments in the news document as there won't be too many comments. Commented Jun 2, 2015 at 5:43
  • Why Is it better to nest comments in news? Commented Jun 2, 2015 at 5:47
  • for example if you want to retrieve news and comments within one query. or maybe you want to stat the comments of each news. Commented Jun 2, 2015 at 6:28

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

How many comments is too many? And Do you think I should put the Following and Follower schema inside UserData as well ?
how many are you expecting? one document is limited to 16MB, you can have a rough estimation how many comments can be commited. As for Following and Follower. I would keep it this way and only save an ID reference. same reason as news group, user name changes.
actually my question is that what is your estimation about number of comments which exceed 16 MB and What if I want to add a LIKE document too? is it still fine to add it to the News Schema?
I actually don't know. what are your users like? what's the average length of comment? you can stat your current website or refer to some similar sites for a reference. the LIKE is ok to be in the News schema. after all it's just an array of user IDs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.