View CouchDb-视图中的Access复制筛选器

View CouchDb-视图中的Access复制筛选器,view,couchdb,View,Couchdb,是否可以使用couchdb的复制筛选器功能(http://wiki.apache.org/couchdb/Replication#Filtered_Replication)通过请求查看,例如: …/_查看/候选?筛选=hrtool/myfilter 根据usersession或userrole筛选文档会更好 提前谢谢 fadh可通过\u列表功能实现 列表函数是Javascript代码,在将视图输出发送到客户端之前对其进行预处理。您可以以任何方式修改视图输出,例如通过过滤某些行 function(

是否可以使用couchdb的复制筛选器功能(http://wiki.apache.org/couchdb/Replication#Filtered_Replication)通过请求查看,例如:

…/_查看/候选?筛选=hrtool/myfilter

根据usersession或userrole筛选文档会更好

提前谢谢


fadh

可通过
\u列表
功能实现

列表函数是Javascript代码,在将视图输出发送到客户端之前对其进行预处理。您可以以任何方式修改视图输出,例如通过过滤某些行

function(head, req) {
  // lists.filtered: filter view output by using a replication filter.

  var ddoc = this; // A common trick to explicitly identify the design document.
  function error(reason) {
    start({"code":400, "headers":{"content-type":"application/json"}});
    send(JSON.stringify({"error":reason}));
  }

  var filter_name = req.query.filter;
  if(!filter_name)
    return error("Need filter_name parameter");

  var filter_src = ddoc.filters[filter_name];
  if(!filter_src)
    return error("Invalid filter_name: " + filter_name);

  // Not 100% sure on this, you could also use new Function(args, src);
  // In the worst-case, the couchapp tool has the !code tool to copy code.
  var filter = eval(filter_src); // Not 100% sure on this
  var row;

  start({"headers":{"content-type":"application/json"}});
  send('{"rows":[\r\n');

  var first = true;
  while(row = getRow()) {
    if(filter(row)) { // Or perhaps use include_docs=true and filter(row.doc)
      if(! first)
        send(",\r\n");
      first = false;
      send(JSON.stringify(row));
    }
  }
  send("]}\r\n");
}
与任何筛选函数一样,使用此列表“筛选”:

GET /db/_design/example/_list/filtered/candidates?filter=myfilter&include_docs=true