Loading TOC...

dls.retentionRule

dls.retentionRule(
   $name as String,
   $comment as Sequence,
   $num-versions as Number?,
   $duration as xs.duration?,
   $document-query-text as String?,
   $document-query as cts.query?
) as element(dls.retentionRule)

Summary

This function creates and returns a retention rule element. Use dls.insertRetentionRule to insert the retention rule into the database.

Specifying multiple constraints implies AND between them. For example, specifying both $num-versions and $duration retains a numbered version only if it is both one of the N most recent versions and it was created more recently than "now - duration." If neither $num-versions or $duration is specified, then any numbered version matching the document query is kept forever.

The $document-query-text parameter is intended to be used for the human readable form of a query that was used to produce the corresponding cts.query . This may be the text that a user typed into a search text field in the UI. This parameter does NOT affect the retention policy.

Parameters
$name The name of the retention rule. The name must be unique to this rule.
$comment Comment that describes this retention rule.
$num-versions The number of most recent versions to be retained. This means to keep versions greater than (but not equal to) num-versions - current-version, if they still exist.
$duration Retain all versions that were created on or after the duration date/time.
$document-query-text Comment that describes the document query.
$document-query The document query. Typically returned by a Query Constructor Function.

Required Privileges

The dls-admin role is required to run this function, or the privilege:
http://marklogic.com/xdmp/privileges/dls-admin

Example

// Returns a retention rule in XML format.

const dls = require('/MarkLogic/dls');

dls.retentionRule(
      'All Versions Retention Rule',
      'Retain all versions of all document',
      null,
      null,
      'Locate all of the documents',
      cts.andQuery(null));
   

Example

// Returns a retention rule in XML format.

const dls = require("/MarkLogic/dls");

  dls.retentionRule(
      "Rule1",
      "Keep the five most recent versions of Jim's documents " +
        "that are 15 days old or newer",
      5,
      xs.duration('P15D'),
     'Locate documents authored by Jim',
      dls.authorQuery(xdmp.user('Jim'))); 
   

Example

// Returns a retention rule in XML format.

const dls = require('/MarkLogic/dls');

  dls.retentionRule(
      'Rule2',
      'Keep the five most recent versions of Jim\'s documents in the "foo" ' +
         'collection that are 15 days old or newer',
      5,
      xs.duration('P15D'),
      'Locate documents in the "foo" collection authored by Jim',
       cts.andQuery([
          cts.collectionQuery('http://marklogic.com/documents/foo'),
          dls.authorQuery(xdmp.user('Jim'))]) );
   

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