MarkLogic Server 11.0 Product Documentation
tde.templateInsert

tde.templateInsert(
   uri as String,
   root as Node,
   [permissions as Object[]],
   [collections as String[]]
) as null

Summary

This function validates the template, inserts the template as a document into the tde collection of the schema database (if executed on the content database) with the default permissions, and reindexes the database.

Note that, when a template is inserted, only those document fragments affected by the template are re-indexed. For more information, see Validating and Inserting a Template in the Application Developer's Guide.

Parameters
uri The URI of the template document to be inserted.
root The template document. The template document can be in either JSON or XML format.
permissions Any permissions to set on the template document. When supplying null as permissions parameter, the inserted template will have the default set of permissions.
collections One or more collections in which to insert the template document.

Usage Notes

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

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

Example

declareUpdate();
const tde = require("/MarkLogic/tde.xqy");

const template = 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"
          }
        ]
      }
    ]
  }
}
);

tde.templateInsert("Template.json", template);
 
// Inserts the template as the Template.json file. 

Example

declareUpdate();
const tde = require("/MarkLogic/tde.xqy");

const template = xdmp.toJSON(
{
  "template":{
    ...
  }
}
);

tde.templateInsert("Template.json", template, [xdmp.permission("role1", "update"), xdmp.permission("role1", "read")]);
 
// Inserts the template as the Template.json file with the specified permissions. 

Example

declareUpdate();
const tde = require("/MarkLogic/tde.xqy");

const template = xdmp.toJSON(
{
  "template":{
    ...
  }
}
);

var perms = [xdmp.arrayValues(xdmp.defaultPermissions(null, 'elements'))];
perms.push(xdmp.permission("role1", "read"));
perms.push(xdmp.permission("role1", "update"));

tde.templateInsert("Template.json", template, perms);
 
// Inserts the template as the Template.json file with the user's default set of permissions and some additional permissions. 
Powered by MarkLogic Server | Terms of Use | Privacy Policy