嘗試用於複製的篩選器時,我偶然發現了一個問題。 雖然我的過濾器是作爲_replicator數據庫中的條目工作的,但我在使用cURL時沒有這樣做。CouchDB篩選複製
設計文檔中的過濾器是:
{
"_id": "_design/partial",
"filters": {
"mobile": "function(doc, req) {
if (doc._attachments) {
var result = new Boolean(true);
for (attachment in doc._attachments) {
if (attachment.content_type == 'image/jpeg') {
return true;
}
if (doc._attachments.length > 1024) {
result = false;
}
}
return result;
} else {
return true;
}
}"
}
}
捲曲行:
curl -X POST http://admin:[email protected]:5985/ _replicate -d '{\"source\":\"http://admin:[email protected]:5984/docs2\",\"target\":\"docs2_partial\",\"filter\":\"partial/mobile\",\"create_target\":true}' -H "Content-Type: application/json"
我創建_design兩個目標和源/部分的文件,但是所有文件被複制。即使是附帶大於1 MB的二進制文件。 任何幫助表示讚賞!
捲曲回覆是:
{"ok":true,"session_id":"833ff96d21278a24532d116f57c45f31","source_last_seq":32,"replication_id_version":2,"history":[{"session_id":"833ff96d21278a24532d116f57c45f31","start_time":"Wed, 17 Aug 2011 21:43:46 GMT","end_time":"Wed, 17 Aug 2011 21:44:22 GMT","start_last_seq":0,"end_last_seq":32,"recorded_seq":32,"missing_checked":0,"missing_found":28,"docs_read":28,"docs_written":28,"doc_write_failures":0}]}
使用任一種 「而不是\」 或「而不是」的結果是:
{"error":"bad_request","reason":"invalid UTF-8 JSON: [...]}
謝謝!將它更改爲'doc._attachments [attachment] .content_type'和'doc._attachments [attachment] .length'就行了。但是,邏輯還有更多,比如允許任何長度的jpegs和我沒有粘貼的更多標準。 – degeeman