flexrep.pullCreate( name as String, domain-id as (Number|String), target-id as (Number|String), urls as String[], http-options as element(flexrep.httpOptions)? ) as element(flexrep.pull)
This function creates a configuration on a Replica database to pull updates from the Master database. If a configuration already exists for the given target and domain IDs, then the configuration is overwritten.
// This query must be executed on a Replica database. const flexrep = require('/MarkLogic/flexrep'); declareUpdate(); const domain = xdmp.eval( 'const dom = require("/MarkLogic/cpf/domains");' + 'fn.data(dom.get("Default Master").xpath("//dom:domain-id"));', null, { 'database' : xdmp.database('Triggers') }); const config = flexrep.configurationCreate(domain); const cfg = flexrep.configurationGet(domain, true); // Specify the ID of the replicated CPF domain obtained from the Master's // Triggers database. const domainId = flexrep.configurationGetId(cfg); // Specify the ID of the replication target obtained from the Master database. :) const targetId = flexrep.configurationTargetGetId(cfg, 'NewReplica'); // Specify the HTTP options for the replication target. const httpOptions = fn.head(xdmp.unquote( '<flexrep:http-options xmlns:flexrep="http://marklogic.com/xdmp/flexible-replication">' + '<http:authentication xmlns:http="xdmp:http">' + '<http:username>replicator</http:username>' + '<http:password>admin</http:password>' + '</http:authentication>' + '</flexrep:http-options>')).root; const pullConfig = flexrep.pullCreate( "Master", domainId, targetId, "http://localhost:8015/", httpOptions); // Insert the pull configuration into the Replica database. flexrep.pullInsert(pullConfig); // Creates a pull replication configuration element for the specified domain.