You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Steffen Mutter <st...@webanimations.de> on 2011/01/29 18:14:48 UTC
Help for reduce function to get view working as needed...
Hello,
I need some help to write a function to reduce a view.
The view actually looks like this:
function(doc) {
emit(doc.heim,null);
emit(doc.gast,null);
}
The reduce function looks actually like this:
function(keys, values) {
return true;
}
The output is nearly the way I want it, but I want to reduce the output,
so that if there is a single (!) number at the end of the key, I want to
cut it off and trim the string if there are spaces left.
The thing behind it is that the CouchDB stores all the matches of the
german handball federation and some of the teams have a number behind
the name of the club, so the view looks like this actually:
"SG Stutensee" true
"SG Stutensee 2" true
"SG Stutensee 3" true
"SG Stutensee 4" true
what I want is, that there's only
"SG Stutensee" true
left, so that I have only (once) the name of the club left.
The next thing is, how to write a view to get all the games the *club*
playes in, so that
"SG Stutensee" would match to all 4 teams.
Kind regards from Germany,
Steffen
Re: Help for reduce function to get view working as needed...
Posted by Randall Leeds <ra...@gmail.com>.
There is no need for a reduce function here since there is no false value.
You want to do all this work in your map() function.
function(doc) {
var heim = doc.heim;
var gast = doc.gast;
//I am not a JS wizard
//Manipulate these values to remove the number
emit(heim, null);
emit(gast, null);
}
That should be all you need. No reduce.
I hope that helps!
Kind regards,
Randall
On Sat, Jan 29, 2011 at 09:14, Steffen Mutter <st...@webanimations.de> wrote:
> Hello,
>
> I need some help to write a function to reduce a view.
> The view actually looks like this:
>
> function(doc) {
> emit(doc.heim,null);
> emit(doc.gast,null);
> }
>
> The reduce function looks actually like this:
>
> function(keys, values) {
> return true;
> }
>
> The output is nearly the way I want it, but I want to reduce the output,
> so that if there is a single (!) number at the end of the key, I want to
> cut it off and trim the string if there are spaces left.
>
> The thing behind it is that the CouchDB stores all the matches of the
> german handball federation and some of the teams have a number behind
> the name of the club, so the view looks like this actually:
>
> "SG Stutensee" true
> "SG Stutensee 2" true
> "SG Stutensee 3" true
> "SG Stutensee 4" true
>
> what I want is, that there's only
> "SG Stutensee" true
> left, so that I have only (once) the name of the club left.
>
> The next thing is, how to write a view to get all the games the *club*
> playes in, so that
> "SG Stutensee" would match to all 4 teams.
>
> Kind regards from Germany,
> Steffen
>