Wildcards in views with CouchDB?

Can wildcards be used in views in CouchDB? For example, let's say I have a database that has teams, player ages, average players, and gender of players. However, the ages of the players cannot be known - they may be from the Dominican Republic or something else. Therefore, I want to use a representation with a map function that can accept non-player age. If I want to get the player with the highest average in the team, regardless of age or with a certain age, how can I do this if I want to use composite keys? For example, you can say that my card emitting function looks something like this:

emit([doc.team, doc.gender, doc.age], doc.average); 

What should I do if I want to pass the key to narrow it, but still the factor is in players who have no age, so instead:

 http://127.0.0.1:5984/savings/_design/players/_view/average?key=["Yankees","male",8] 

does something that includes a wildcard, for example, to get averages regardless of age:

 http://127.0.0.1:5984/savings/_design/players/_view/average?key=["Yankees","male",*] 

Is it possible to write a presentation in CouchDB to do something like this? Or do I need to write a few views and process them separately?

Thanks,
Ben

+7
couchdb nosql mapreduce
source share
2 answers

You can specify startkey and endkey and use the "wildcard" {} , an empty JavaScript object:

 http://127.0.0.1:5984/savings/_design/players/_view/average?startkey=["Yankees","male",0]&endkey=["Yankees","male",{}] 
+13
source share

A wildcard is not possible, but you can specify startkey and endkey :

 http://127.0.0.1:5984/savings/_design/players/_view/average?startkey=["Yankees","male",0]&endkey=["Yankees","male",999] 
+7
source share

All Articles