couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joel Reed <>
Subject Re: using reduce to get SQL distinct like results
Date Wed, 27 Aug 2008 01:19:16 GMT
Chris Anderson wrote:
> I would avoid using a reduce at all in this case, and just request the
> key-range corresponding to the particular user directly from the map.
OK, but just to be clear, the data set I want to display would be 
something like

User 1 -- Dates: 11/02/2003, 12/02/2004, 1/02/2005
User 2 -- Dates: 3/12/2004, 10/02/2005, 1/02/2006
User 3 -- Dates: 4/12/2003, 6/02/2006, 1/02/2006


You wouldn't advise me to make multiple calls to the same view for each 
user would you? Once to get list of all users, then once for every user? 
I was thinking that maybe in this case I should be using a reduce 
function. What would you advise?


> You'll get all the information you need, and little extraneous
> information. You can then munge the data into whatever shape you need
> in your application. However, I bet you won't need to do much munging.
>  "all": {
>    "map": "function(doc) { emit(doc.User, doc.Date); }"
>   }
>  }
> Reduce should be reserved for when you want to aggregate a scalar
> value from a set of map rows. Eg, the number of messages a user
> received in a given month, or some such. When you merely want all the
> data from a map, about a given key, just query the map.
> Chris

View raw message