简体   繁体   中英

Database project in MongoDB

I write social media application and I am new in noSQL databases. I would like to ask about some advice and opinion about my database project.

@Updated image 在此处输入图片说明

Also I want to do one more table for notification (when someone comment, like our post/comment and when someone accept our invitation to friends). I thought about make 3 different tabels - notification_post, notification_comment, notification_friend_accept, but I don't if this is good idea...

Looks like your database is prety relational, this is a strong indicator to use a relational database, but let's go!

When we design noSQL databases, like MongoDB, we need to avoid normalization, or "over normalization". This means that is more interesting repeat than avoid duplications.

There is some design patterns to MongoDB, and maybe the easiest one is Extended Reference . You'll find this useful when a lot of joins are needed to retrieve data. This design pattern tells to duplicate the most frequent data. Another one is subset , this will probably help.

Every time you bring a post, probably you'll show the comments number, some comments, likes number and so on. With this in mind, you can put your likes objects inside comments and posts, removing the collection. This avoid a second lookup on another collection. Probably remove the last_like property and sort the "likes array" descending by date and pull the first one.

Remember, documents in MongoDB are atomic, they are full loaded on RAM before any filtering.

You certainly can do it that way, but keep in mind you are going to have to do 3x queries. Perhaps a generic Notification{ notifcationTypeEnum: 'abc', ...} would be more appropriate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM