couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Florian Westreicher Bakk.techn." <>
Subject Re: Design Question: What is a Good Model?
Date Tue, 08 Oct 2013 20:31:15 GMT
I'm also new but I would just use a view for that. You can emit user names as key and favorites
as values and later query it with key=username

function map(doc) {
if(doc.type === 'favorite') {
emit(doc.user, doc.favorite_id);


(coding on mobile is hard)

Benjamin Reed <> wrote:
>I'm extremely new to CouchDB, and to NoSQL and map/reduce in general. 
>was wondering, what is the best way to design what I'm trying to
>I'm writing an app, which will have a collection of (calendar) events,
>created by users.  Users will be able to mark events created by other
>as favorites.
>In a traditional database, I'd have at least 2 tables:
>- an event table, with a column representing the user that created the
>- a "favorites" table, which maps a user to an event that he has
>- optionally, a user table with info about the user, and a unique ID
>can be used in lieu of username in the first 2 tables when making
>In the (web) app I'm writing, I've got the events in couchdb:
>   _id: whatever,
>   type: 'event',
>   summary: 'foo',
>   description: 'bar',
>   createdBy: 'RangerRick'
>But what is the best way to retrieve the "favorites" associated with a
>specific user?  Do I just make a doc with an ID set to
>"RangerRick-favorites" and retrieve it directly?  Do I just put
>username -> _id entries in for each favorite?
>I currently am doing the latter, which didn't seem like a big deal
>until I
>had to pull just the list of events that match the favorites, and can't
>figure out how to make a map/reduce that does it efficiently.
>Do I just map anything that's a type=favorite or type=event and then...
>reduce it somehow by putting them together?

Sent from Kaiten Mail. Please excuse my brevity.

View raw message