CouchDB Replication Filtering

Having tried filters for replication, I came across a problem. Although my filter works as an entry in the _replicator database, I do not use cURL.

Filter in the project document:

{
    "_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 line:

curl -X POST http://admin:pass@192.168.178.13:5985/_replicate -d '{\"source\":\"http://admin:pass@192.168.2:5984/docs2\",\"target\":\"docs2_partial\",\"filter\":\"partial/mobile\",\"create_target\":true}' -H "Content-Type: application/json"

I created a _design / partial document for both the target and the source, but all documents are replicated. Even one that has an attached binary file larger than 1 MB. Any help is appreciated!

CURL answer:

{"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}]}

Using "instead of \" or "instead", the result:

{"error":"bad_request","reason":"invalid UTF-8 JSON: [...]}
+5
source share
2 answers

Now I think that maybe the logic of your filter function just has an error. This is how I read your filter policy:

  • , ,
  • , image/jpeg
  • 1,024
  • docs

. : " 1024 , ". , , , .

, . :

for (attachment in doc._attachments) { /* ... */ }

attachment , "index.html" "me.jpeg", . , :

var type;

// This is WRONG
type = attachment.content_type; // type set to undefined

// This is RIGHT
type = doc._attachments[attachment].content_type; // type set to "text/html" etc.

, , :

for (attachment_filename in doc._attachments) { /* ... */ }

doc._attachments.length , . , , . ?

+8

curl (.. CouchDB)?

, , . . . ?

Windows, . .

0

All Articles