I'm trying to do a personal blog system with MongoDB. The blog system designed to support both formal article and short tweets, which have similar but different data structures. For example, an article must have a title, but tweets must not; both them have a creation date.
There is also a timeline feature in design. The timeline will show latest 10 items, no matter the item is an article or a tweet, and when "load more" button pressed, there will show the 10-20 items...
So I think there are two method to design the database schema
- Save articles and tweets into separate collections.
- Save all things into a single collection, add a "type" field for specifying.
And I have three questions:
- If I use method 1, how to implement the "latest 10 items" query? Any literal explanation, or example code in MongoDB query language, mongoose, mongoengine or else, is welcome.
- If I use traditional SQL DB (like MySQL), is there a common method to solve the "latest 10 items" problem ?
- Which methods fits the MongoDB's philosophy more ?
Thanks