Kevin
Kevin

Reputation: 1157

Dynamic collection design of mongodb

I am designing notification center for a social network, and I am just thinking about to store one user's notifications in one collection named notification_$userid ($userid is dynamic).

And for such design, I think that can be read and writed faster than putting all users' notifications in only one collection. But is there any disadvantage for it? or is there any limitation for collection amount of one db?

Upvotes: 0

Views: 1181

Answers (1)

benqus
benqus

Reputation: 1139

I think you might want to rethink this. The reason is that no matter how flexible is a noSQL database, it can be still huge. And the sharding, and if you grow later you might want to consider migrating to a cluster, etc. I would recommend you that you solve this task on the application layer.

Here's how I would do:

1) user comes, makes something that notifies the other users 2) this "gesture" is not stored in your database as notifications, but in the related user "notifiocations" cell. 3) the user's "noticifcations" cell is similar to an array - in MongoDB it is an array and you just store objects there

This way you "personalize" your notifications in your DB also and you have avoided using a "notifications" collection. The only thing you need to do is to push that notification into the related users "notifications" array.

Upvotes: 1

Related Questions