A few questions about storing user data in MongoDB. What is the best place in mongo to store user specific data, such as User settings, User photo url, User friends, User events?
In Mongo, user data is stored in: Meteor
/ Collections
/ users
/ _id
/ profile
/ services
Should I add there a new collections? In a following way:
/ events / _id's
/ friends / _id's
/ messages / _id's
/ settings
How should I publish user's private data and manipulate this collections, to be sure it's save and no one else will modify or have access to private data of another person.
Normalization
"Database normalization is the process of organizing the attributes and tables of a relational database to minimize data redundancy."
MongoDB is a non relational database. This makes normalized data hard to query for. This is why in MongoDB we denormalize data. That makes querying for it easier.
It depends on your use-case. The question is basically when to demormalize. It's mostly a matter of opinion. But objective here are some pros and cons:
Pros to demormalization
Cons to demormalization
user.messages
(You can't just publicize some messages)In your case I'd definitly go for seperate collections for
events
,friends
andmessages
. Setting can't expand infinitly. So I'd put it into theusers
collection.Security
I'd use a publications and allow and deny for this. Let me make an example for
Messages
:Collection
Publication
Allow
This code is untested, so it might contain small errors