I have a mysql database containing tables like User, playlist, videos, tags.
Based on this I would like to collect the user activity on the application. the example use cases may be :
a.) (user) joined (app) on (date)
b.) (user) created playlist (playlist) on (date)
c.) (user) added (video(s)) to playlist (playlist)
d.) (user) added tags (tag(s)) to video in playlist (playlist)
Given such data, which would be better alternative to design a user activity schema? relational(I am using MySQL) or NoSQL(non-relational, like MongoDB)
Favoring NoSQL
a.) The other thing is sin开发者_如何学JAVAce activity lit will be huge, retrieving data should be fast, I read Document Oriented database performs well in such scenarios since no joining between the tables is needed b.) Since the activity log may contain no,one,many variables depending upon the activity happening, a relational schema might not be a good solution.I would like to learn more about it, please share the knowledge :)
You are correct, main problem in any relational database is join.
So, you can create tracking system in mongodb or in mysql, just avoid joins:
So structure will be like this:
id
activity_type - int
user_id
date
field1
field2
filed3
where activity_type (Signup = 1, CreatedPlaylist =2, ...)
To avoid join with user table you should add some user related data (data, that you need display, like first_name, last_name) to each activity row.
With provided above solution you can stay with mysql, and speed will same. Mongodb will be faster when you embedd in document many things, that you need join in relational database.
As a long-time Relational user, it seems to me the decision hinges on whether or not you have financial transactions or the tracking of physical goods. The "money and stuff" is what Relational was invented for. It is extremely good at it and maintains a very high standard of correctness.
However, when you do not have to balance books, or make sure you don't accidentally sell more widgets than you have, then use what you are comfortable with. Mongo, Couch, whatever.
精彩评论