Loading TOC...


   doc as Node[],
   rule-collection as String[]
) as Sequence


Apply redaction rules to a set of XML and/or JSON documents, returning the resulting documents.

doc The documents to which to apply redaction rules. Only XML and JSON documents can be redacted.
rule-collection The URIs of collections of redaction rules to apply to the input nodes. The collection(s) can contain XML rules, JSON rules, or both, but must not contain non-rule documents.

Required Privileges

This operation requires the redaction-user role or the following privilege:


Usage Notes

This function applies redaction rules to a set of input documents. If no rules match a node, the node is returned unchanged. The collections named in $rule-collections can only contain redaction rule definitions.

You should validate your rules before using them to redact content. An invalid rule will cause this function to throw an exception. Use rdt.ruleValidate to validate a redaction rule collection.

Install rules in the schema database associated with your content database.

See Also


// ------------------------- Script 1 ------------------------------
// Install a redaction rule using the built-in 'redact-us-ssn' redaction
// function. The rule is installed in the 'pii-rules' collection. The
// context database for the rule insertion must be the schema database.


  { rule: {
      description: 'hide ssn',
      path: '//ssn',
      method: { function: 'redact-us-ssn' },
      options: { level: 'partial' }
  }}, xdmp.defaultPermissions(), ['pii-rules']);

// ------------------------- Script 2 ------------------------------

// The following is a SEPARATE STEP (script) that uses the installed rule
// to redact documents in the "people" collection. The context database
// is the content database.
// Note that since rdt.redact expects a document node as input and
// match.document is the root node under the document node, fn.root
// is used to access the parent document node.

const jsearch = require('/MarkLogic/jsearch');
const rdt = require('/MarkLogic/redaction');

    .map(function (match) { 
        match.document = fn.head(
          rdt.redact(fn.root(match.document), 'pii-rules')
        return match;

// The returned search result object contains the redacted content
// in results[i].document.

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