Is it possible to use wildcards in views in CouchDB? For example, lets say I have a database that has teams, ages of players, players' averages, and gender of players. However, the players' ages may not be known - they could be from the Dominican Republic or whatnot. So I want to use a view with a map function that can accept not having the player's age. If I want to get the player with the highest average on a team regardless of age or with a specific age, how do I do so if I want to use compound keys? For example, lets say my map emit function is something like:
emit([doc.team, doc.gender, doc.age], doc.average);
What do I do if I want to pass in a key to narrow it down, yet still factor in the players who don't have an age entered, so instead of:
http://127.0.0.1:5984/savings/_design/players/_view/average?key=["Yankees","male",8]
doing something that incorporates a wildcard such as this to get the averages regardless of age:
http://127.0.0.1:5984/savings/_design/players/_view/average?key=["Yankees","male",*]
Is it possible to write a view in CouchDB to do something like this? Or do I need to write multiple views and process them separately?
Thanks,
Ben
You can specify startkey
and endkey
and use the "wildcard" {}
, a JavaScript empty object:
http://127.0.0.1:5984/savings/_design/players/_view/average?startkey=["Yankees","male",0]&endkey=["Yankees","male",{}]
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With