Note to self: I now realize that the easiest way (perhaps the best) to
do the below is to have your function be
map: function(doc) {
if (doc.Experiment)
for (i in doc.Conditions){
emit([doc.Experiment, i], 1);
}
}
reduce: function(key,values,rereduce)
{
return sum(values);
}
This gives you rows like
{"key":["Something","X"],"value":3}
{"key":["Something","Y"],"value":4}
where value is the count.
You can replace 1 and the sum with null if you're not interested in
the count.
This is way better than a unique() function because it calculates in
constant time and memory and you can request subranges of values.
Wout.
On Mar 3, 2009, at 2:38 PM, Wout Mertens wrote:
I believe this has been covered in this thread:
http://markmail.org/thread/lwqfwlscrvilwm34
but I think a totally satisfactory answer was not found.
Wout.
On Mar 3, 2009, at 2:27 PM, Manolo Padron Martinez wrote:
Hi:
I'm really a newbie, and I have a newbie problem (and maybe a miss
conception of the way to work with couch).
I have a lot of documents with this form (that represents
experiments with
any number of conditions, so X and Y could be only X or even
X,Y,Z...)
{
"Experiment":"something",
"Conditions":
{
"X":3,
"Y":2
}
}
And I have a view like:
MAP:
function(doc) {
if (doc.Experiment)
for (i in doc.Conditions){
emit(doc.Experiment, i);
}
}
REDUCE:
function(key,values)
{
return values;
}
When I launch the view I get this:
{"rows":[{"key":"Something","value":["X","Y"]},
{"key":"Something2","value":
["X","Y","X","Y","X","Y","Z","X","Y","X","Y","X","Y","Z"]}]}
I would like to get what are the conditions for every experiment
grouped by
experiment without repetitions (I mean something like)
{"rows":[{"key":"Something","value":["X","Y"]},
{"key":"Something2","value":["X","Y","Z"]}]}
Anyone could help me?
Regards from Canary Island
Manuel Padron Martinez