Is it possible access a requests querystring parameters in a view?
Consider this request... GET/database/_designs/foo/?bar=1
And this map...
views {
foo: {
map: function (document)
{
// I want to access querystring parameter "bar" here! But how?
// I'd like to be able to do something along the lines of...
if (bar > 0) emit(null, document);
}
}
}
From http://sitr.us/2009/06/30/database-queries-the-couchdb-way.html:
The CouchDB design gets you great performance on large data sets. But it means that you cannot pass dynamic parameters to your map function when you run a query. You cannot ask for it to emit only user records with a given last name unless you want to maintain a special view for that particular last name. In most cases it is not practical to build separate views for every query that you might want to run someday. So what you can do is to run a query against the general purpose view above and request only key/value pairs that match a particular key.
function find_users_by_last_name(db, last_name) {
var matches;
matches = db.view('users/last_names', { key: last_name });
return matches.rows.map(dot('value'));
}
So, no, but you can query against a view.
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