Dear Wiki user, You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.
The "Replication" page has been changed by RobertNewson. http://wiki.apache.org/couchdb/Replication?action=diff&rev1=19&rev2=20 -------------------------------------------------- {"source":"http://example.org/example-database","target":"http://admin:[email protected]:5984/example-database", "continuous":true, "cancel":true} }}} + === Filtered Replication === + + Sometimes you don't want to transfer all documents from source to target. You can include one or more filter functions in your design document and then tell the replicator to use them. + + A filter function takes two arguments (the document to be replicated and the the replication request) and returns true or false. If the result is true, then the document is replicated. + + {{{ + function(doc, req) { + if (doc.type && doc.type == "foo") { + return true; + } else { + return false; + } + } + }}} + + Filters live under the top-level "filters" key; + + {{{ + { + "_id":"myddoc", + "filters": { + "myfilter": "function goes here" + } + } + }}} + + Invoke them as follows; + + {{{ + {"source":"http://example.org/example-database","target":"http://admin:[email protected]:5984/example-database", "filter":"myfilter"} + }}} + + You can even pass arguments to them; + + {{{ + {"source":"http://example.org/example-database","target":"http://admin:[email protected]:5984/example-database", "filter":"myfilter", "query_params": {"key":"value"}} + }}} See also: * [[Replication_and_conflicts|Replication and conflicts]]
