Map / Zoom out in CouchDB with multiple options?

I am wondering how to use CouchDB map / reduce with multiple parameters. For example, if I have teams that have players with age and gender, I assume that I will do this for my map function:

"function(doc){
  if(doc.team_name) {
    emit(doc.team_name, doc);
  }
}"

However, I am not sure how to write a reduction function to get the oldest male player on the team or the youngest woman or any other arbitrary request. Can I pass parameters in the url or do I need to write multiple views?

Thanks in advance
Ben

+3
source share
1 answer

. . , , , .

, emit [team, age]. .

function(doc) {
  if (doc.team_name) {
    emit([doc.team_name, doc.age], doc);
  }
}

. descending=true, . . , (- ) : startkey=[<team>, 999]&endkey=[<team>,0]&descending=true

+5

Source: https://habr.com/ru/post/1763495/


All Articles