Loading TOC...

flexrep:inbound-filter-insert

flexrep:inbound-filter-insert(
   $filter as element(flexrep:inbound-filter)
) as empty-sequence()

Summary

This function inserts an inbound filter configuration into the database. A single inbound filter applies to all inbound flexible replication to the database. The filter receives two external variables as input, and should return the filtered form of the replication information. An example is shown below.

Parameters
filter An inbound filter configuration.

Example


xquery version "1.0-ml"; 
  
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

flexrep:inbound-filter-insert(
  flexrep:inbound-filter-create(
    "/my-inbound-filter.xqy",
    <flexrep:filter-options xmlns="xdmp:eval">
      <modules>{xdmp:database("my-modules-database")}</modules>
      <root>/some/directory/</root>
    </flexrep:filter-options>))
    

The following example shows an identity filter, that also inserts a log document into the database to track the inbound replication information.

xquery version "1.0-ml";

import module
  namespace flexrep = "http://marklogic.com/xdmp/flexible-replication"
  at "/MarkLogic/flexrep.xqy";

declare namespace doc = "xdmp:document-load";

declare variable $dts as element(flexrep:domain-target-status) external;
declare variable $update as node()* external;
	        
xdmp:document-insert(
  "/inbound-log/" || xdmp:random() || ".xml",
  <inbound-log time="{fn:current-dateTime()}">
    { for $u in $update
      let $exists :=
        attribute exists {
          fn:exists(
            ( fn:doc($u/doc:uri),
              xdmp:document-properties($u/doc:uri)
            ))
        }
      return
	typeswitch ($u)
	case element(flexrep:update)  return
	  element flexrep:update {
	    $exists,
	    $u/@*,
	    $u/*
	  }
	case element (flexrep:delete) return
	  element flexrep:delete {
	    $exists,
	    $u/@*,
	    $u/*
	  }
	default return ()
    }
  </inbound-log>,
  ("read", "update") ! xdmp:permission("flexrep-user", .)),

$update	        
    

The $dts variable can be used to determine where the inbound replication is coming from. Below is an example. The received-from element is either the IP address that a push is coming from, or the URL that was used if the replication was the result of a pull.

<document-target-status xmlns="http://marklogic.com/xdmp/flexible-replication">
  <domain-id>82381923712932</domain-id>
  <domain-name>Default Documents</domain-name>
  <target-id>637261830239283</target-id>
  <target-name>San Francisco</target-name>
  <received-from>10.100.42.3</received-from>
  <received-at>2014-11-20T16:14:57.876111-08:00</received-at>
</document-target-status>
    

Required Privileges

http://marklogic.com/xdmp/privileges/flexrep-admin

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.