I'm trying to model a simple, experimental app as I learn Symfony and Doctrine.

My data model requires some flexibility, so I'm currenty looking into the possibility of using either an EAV model, or document store in MongoDB.

Here's my basic requirements:

Users will be able to store and share their favourite things (TV prog, website, song etc).

The list of possible 'things' a user can store is unknown. For example, a user may want to store their favourite animal.

Users can share their favourite things with other users. However, a user can decide what he / she shares with each other user. For example, a user may share their favourite movie with one user, but not another.

A typical user will log in and view all the favourite things from their list of friends, depending on what his friends have decided to share. The user will also update their own favourite things, which will be reflected when each other users views their own profile. Finally, the user may change which of his friends can see what of his favourite thing.

I've worked a lot with Magento, which uses the EAV model extensively. However, I'm adding another layer of complexity by restricting which users can see what information.

I'm instantly drawn to MongoDB as the schemaless format gives me the flexibility I require. However, I'm not sure how easy (or efficient) it will be to access the data once it's saved. I'm also concerned about how changes to the data will be managed, e.g. a user changes their favourite film.

I'm hoping someone can point me in the right direction. This is purely a demo app I'm building to further my knowledge, but I'm treating it like a real-world app where data access times are super-important.

Modelling this kind of app in a traditional relational DB makes me sweat when I think about the crazy number of joins I'd need to get the data for one user.

Thanks for reading this far, and please let me know if I can provide anymore information.

1 Answer
1

If you just need to filter out some values when viewing the user profile, a single document for each user would work quite well, with each favorite within that having a list of authorized user/group IDs that is applied in the application code. Both read and write are single operations on a known document in this case, so will be fast.

If you need views across multiple profiles though, your main document should probably be the favorite. You'll need to set up the right indexes, but performance shouldn't be a problem.

Actually, the permissions you describe don't add that much complexity to an EAV schema - as long as attributes can have multiple values the permissions list is just one more attribute.

Hi - thanks for the replay. Since the app will access data much more than it will write data, I'm thinking that perhaps when a user saves or edits their favourites, it embds a copy in each user document. That way it each user can quickly access what other users have granted them access to. It does mean that writing data will be more of an overhead, but this is not so much of a concern.
–
NeglectedGoldfishAug 7 '11 at 20:35