Hi Marian

I am still pretty new around here myself, but it seems like what you are doing 
is an extension of the blog post & comments model.

http://www.cmlenz.net/archives/2007/10/couchdb-joins

You would just need to extend it a bit to have two references per access object 
– one for the song and one for the user. Then create views that show songs by 
user and users by song – what ever you need.

David

From: Marian Steinbach 
<marian.steinb...@gmail.com<mailto:marian.steinb...@gmail.com>>
Reply-To: "user@couchdb.apache.org<mailto:user@couchdb.apache.org>" 
<user@couchdb.apache.org<mailto:user@couchdb.apache.org>>
Date: Sat, 12 Nov 2011 15:26:58 -0500
To: "couchdb-u...@apache.org<mailto:couchdb-u...@apache.org>" 
<couchdb-u...@apache.org<mailto:couchdb-u...@apache.org>>
Subject: Document design: Logging accesses to an item by a user

Hi!

I'm trying to think in CouchDB documents (coming from an SQL
perspective) and I am wondering how I should set up my documents to
represent the following.

I have users who play songs as often as they want. Whenever they
access a song, in the SQL world I add a record to a song_access table
that stores user id, song id and date/time. And there are of course a
users and a songs table.

In the CouchDB world, I find it reasonable to have both a User
document and Song document. But where should I store song accesses?

- Should it be on the User as a dict of song_id and timestamp (or vice versa),
- or should ie be on the Song with a user id and timestamp?
- or would it be worthwhile to do such a thing in a third document
SongAccess, which has one user id, one song id and possible multiple
timestamp?

The list of song accesses per user and also per song can grow very
large of course. Is this a good reason to leave it out of User/Song?

I would later need a view that lists all songs heard by a user in
chronological order.

The same design problem I have for ratings, although here I have song
id, user id, date/time and score.

Thanks for ramping me up!

Marian

Reply via email to