MongoDB - correct use of collections?
In Mongo, I understand that you can have databases and collections. I am working on a social application that will have blogs and comments (among other things) and have previously used MySQL and fairly heavy partitioning to limit possible concurrency issues.
With MySQL, I have populated all my user data into the _user database with multiple tables to separate the data (blogs, pages, etc.).
My immediate reaction with Mongo would be to create a user database with one collection per user. This way, zach's blog entries will go into the "zach" collection with associated comments and such become subobjects in the same collection. Basically like dynamically creating one table per user in MySQL, but seemingly without the complexity and constraints it might impose.
Of course, since I hadn't used Mongo yet, before I had problems measuring (um ...) the quality of this idea and potential problems that might come up in the future.
I would like the user data to be handled in the same way as the user directory in a * nix environment where the user created / not shared (mostly) is put in one place (currently with MySQL, which will be appname_users as above).
Most of the user data will be specific to user pages. Some user data that is requested from all site users (search user profiles) is currently stored in a separate database / table and I expect things like this can be put into the appname_system database and broken down into collections and / or database applications (appname_profiles).
Anyway, since the available documentation on the subject is a bit thin at the moment and my experience is extremely limited, I thought I could find a little tutorial from someone who has a better understanding of the system.
On the plus side, I've actually tried to treat MySQL as a schema-less document store before, and doing it with Mongo seems much more intuitive / sane / rational, so I'm looking forward to getting started.
Thanks, Zach
source to share
I have the same application.
Some things to consider: you can cross query between collection bu not between databases. So it's probably best to have a database with all of your data, and then a collection for each object.
Then each document can contain any kind and number of fields.
I was trying to avoid inlining b / c arrays I was having trouble requesting my object correctly (it worked fine, but my system architecture was designed for this use)
And the database can be shared among multiple servers automatically, so space is not a problem (if you have more than one server)
source to share