2

CouchDB 方便本地开发(CouchApps),然后推送到远程生产。不幸的是,对于生产规模的数据集,处理视图可能很麻烦。

在本地开发中使用 CouchDB 数据库样本的好方法是什么?

4

1 回答 1

2

答案是过滤复制。我喜欢分两部分来做这件事:

  1. 将生产数据库复制example_db到我的本地服务器example_db_full
  2. example_db_full从to执行过滤复制example_db,其中过滤器会切掉足够的数据,因此构建速度很快,但会保留足够的数据,以便我可以确认我的代码有效。

要选择的文档可以是特定于应用程序的。目前,我对简单的随机通过/失败以及我可以指定的百分比感到满意。随机性是一致的(即,相同的文档总是通过或总是失败。)

_rev我的技术是在 [0.0, 1.0) 范围内规范化文档字段中的内容校验和。然后我简单地指定一些分数(例如0.01),如果标准化校验和值 <= 我的分数,则文档通过。

function(doc, req) {
  if(/^_design\//.test(doc._id))
    return true;

  if(!req.query.p)
    throw {error: "Must supply a 'p' parameter with the fraction"
                  + " of documents to pass [0.0-1.0]"};

  var p = parseFloat(req.query.p);
  if(!(p >= 0.0 && p <= 1.0)) // Also catches NaN
    throw {error: "Must supply a 'p' parameter with the fraction of documents"
                  + " to pass [0.0-1.0]"};

  // Consider the first 8 characters of the doc checksum (for now, taken
  // from _rev) as a real number on the range [0.0, 1.0), i.e.
  // ["00000000", "ffffffff").
  var ONE = 4294967295; // parseInt("ffffffff", 16);
  var doc_val = parseInt(doc._rev.match(/^\d+-([0-9a-f]{8})/)[1], 16);

  return doc_val <= (ONE * p);
}
于 2010-08-30T21:02:41.207 回答