是否可以在视图中访问请求查询字符串参数?
考虑这个要求...... GET/database/_designs/foo/?bar=1
而这张地图......
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
Chr*_*ain 14
来自http://sitr.us/2009/06/30/database-queries-the-couchdb-way.html:
CouchDB设计可以在大型数据集上获得出色的性能.但这意味着在运行查询时无法将动态参数传递给map函数.您不能要求它仅发出具有给定姓氏的用户记录,除非您要为该特定姓氏维护特殊视图.在大多数情况下,为您可能希望某天运行的每个查询构建单独的视图是不切实际的.因此,您可以执行的操作是针对上面的通用视图运行查询,并仅请求与特定键匹配的键/值对.
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'));
}
Run Code Online (Sandbox Code Playgroud)
所以,不,但您可以查询视图.