Loading TOC...

tde.templateBatchInsert

tde.templateBatchInsert(
   template-infos as Object[]
) as null

Summary

This function validates and inserts multiple templates, is similar to tde.templateInsert for individual template, throw errors for any invalid template or duplicate template URIs provided by sequence of argument with tde.templateInfo.

Before inserting, validates each new template against all other new and existing (not in the new URIs list) templates with same schema/view-name. Any existing template with the same URI in the new URIs list will be ignored and replaced directly even if the new template has same URI but different schema/view-name.

Parameters
template-infos A sequence of maps that specify the template information (URI, template, permissions, collections) to apply as produced by tde.templateInfo.

Usage Notes

The tde-admin role is required in order to insert templates into the schema database.

Note that this is a library function that requires that you import the tde.xqy module.

Example

declareUpdate();
var tde = require("/MarkLogic/tde.xqy");
var t1 = xdmp.toJSON(
{
  "template":{
    "context":"/MedlineCitation/Article",
    "rows":[
      {
        "schemaName":"Medical",
        "viewName":"Publications",
        "columns":[
          {
            "name":"ID",
            "scalarType":"long",
            "val":"../MedlineID"
          },
          {
            "name":"ISSN",
            "scalarType":"string",
            "val":"Journal/ISSN"
          }
        ]
      }
    ]
  }
}
);
var t2 = xdmp.unquote(`
<template xmlns="http://marklogic.com/xdmp/tde">
  <description>populates patients' data</description>
  <context>/MedlineCitation/Article</context>
  <rows>
    <row>
      <schema-name>Medical</schema-name>
      <view-name>Publications</view-name>
      <columns>
        <column>
          <name>ID</name>
          <scalar-type>long</scalar-type>
          <val>../MedlineID</val>
        </column>
        <column>
          <name>ISSN</name>
          <scalar-type>string</scalar-type>
          <val>Journal/ISSN</val>
        </column>
      </columns>
    </row>
  </rows>
</template>`);

tde.templateBatchInsert(
  [ tde.templateInfo("t1.json",t1),
    tde.templateInfo("t2.xml",t2),
    tde.templateInfo("t3.xml",xdmp.documentGet("/temp/t3.xml"),
      [xdmp.permission("role1","update"),
       xdmp.permission("role1","read")
      ],
      ["collectionA"]
    )
  ] 
);

// Inserts 3 templates as t1.json, t2.xml, t3.xml (with the specified permissions and collectionA). 

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