I need an advice about NoSQL/MongoDb and data/models structure

couchdb, database, mongodb, nosql

Solution

I would suggest storing votes as a list of story `_id`s in each user. That way you can find out what stories a user has voted for just by looking at the list. To get the users who have voted for a story you can do something like:

`db.users.find({stories: story_id})`

where `story_id` is the `_id` of the story in question. If you create an index on the `stories` field both of those queries will be fast.

Problem

Recently I'm exploring NoSQL Databases. I need an advice about how to store data in the most optimal and efficient way for a given problem. I'm targeting MongoDB, now. However it should be the same with CouchDB. Let's say we have these 3 Models: ``` Story: id title User: id name Vote: id story_id user_id ``` I want to be able to ask the database these questions: - Who has voted for this Story? - What this User has Voted for? I'm doing simple joins while working with a relational DB. The question is, how should I store the data for those objects in order to be most efficient. For example, if I store the Vote objects as a subcollection of Stories it wont be easy to get the info - "What a user has voted for".

Original source

Related problems