rdt.redact( 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.
redaction-user
role or the
following privilege:
http://marklogic.com/xdmp/privileges/redaction-user
$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.
// ------------------------- 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. declareUpdate(); xdmp.documentInsert('/redactionRules/ssn.json', { 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'); jsearch.collections('people').documents() .map(function (match) { match.document = fn.head( rdt.redact(fn.root(match.document), 'pii-rules') ).root; return match; }).result(); // The returned search result object contains the redacted content // in results[i].document.
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.