I have a question that involves a performance question and Mongo Design. Currently a project I am working on will involve notifications similar to Facebook where a user will receive messages on things that happen in the site. The problem is choosing if notifications will be either be its own collection or an array embedded within a user. Requirements of notifications include:
- Changing the status from read/unread, and ordering by date(other sorting maybe later).
- Notifications are suppose to be in real time .
- Notifications are deleted every 2 weeks.
我认为,如果我错的话,我就不明白了。
If the notifications are embedded in the user document, they will be slower, more costly, and more time developing and harder to maintain because:
For ordering and sorting, they will have to be map reduced for finding only the unread and ordering by a date. Or this can be done by PHP but is a more lengthily process.
Updating/Deleting a notification record in an embedded array takes more time to find that document and can be prone to errors if an index of a notification has changed (IE: A new notification is push into the document).
Notifications will be added to a queue in PHP and/or JavaScript for retrieval later. It will more time spent trying to figure out how to modify the queue(append/remove) because they will not have IDs.
If they are stored in their own collection and each notification has its own id.
不需要减少地图,更容易找到和分类。
Maybe possibly have performance issues if there are a lot of notifications(Is this true or false?).
由于有女婴,请更新询问。
Easier and can more reliably update and remove notifications because IDs do not change.
我能否得到这方面的一些反馈? 我的逻辑是否正确?