答案是过滤复制。我喜欢分两部分来做:
-
复制生产数据库,
example_db
example_db_full
-
从执行筛选的复制
示例\u db \u full
到
示例\u db
要选择的文档可以是特定于应用程序的。在这个时候,我对一个简单的随机通过/失败的百分比感到满意。随机性是一致的(即,相同的文档总是通过或失败)
我的技术是规范文档中的内容校验和
_rev
范围为[0.0,1.0]的字段。然后我简单地指定一些分数(例如。
0.01
),如果规范化的校验和值为<=my fraction,则文档通过。
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);
}