Home > Mobile >  Invalid TDE template
Invalid TDE template

Time:06-03

My MarkLogic database consists of a couple of sample documents in the folder "patents":

  • /patents/airless_diving.json
  • /patents/smart_racket.json
  • /patents/tuning_ukulele.json
  • /patents/waterski_drone.json

Each document looks like that:

{
  "patent": {
    "title": "Airless SCUBA diving", 
    "inventor": "Greg", 
    "description": "Diving pill that provides airless SCUBA diving for up to 1 hour"
  }
}

I am trying to create a template:

    const tde = require ('/MarkLogic/tde');
    
    const inventionsTemplate = xdmp.toJSON(
    {
      'template':{
        'context':'patent',
        'directories':["patents", "another_patents"],
        'rows':[
        {
          'viewName':'inventions',
          'columns':[
          {
            'name':'title',
            'scalarType':'string',
            'val':'../title',
            'nullable':true
          },
          {
            'name':'inventor',
            'scalarType':'string',
            'val':'../inventor',
            'nullable':true
          },
          {
            'name':'description',
            'scalarType':'string',
            'val':'../description',
            'nullable':true
          }
          ]
        }]
      }
    }
    );

tde.templateInsert('/templates/inventionsTemplate.json', inventionsTemplate);

But getting an error:

[javascript] TDE-INVALIDTEMPLATE: (err:FOER0000) tde.templateInsert('/templates/inventionsTemplate.json', inventionsTemplate); -- Invalid TDE template: TDE-INVALIDTEMPLATENODE: Invalid extraction template node: fn:doc("")/template/array-node("rows")/object-node()

Stack Trace At line 75 column 6: In tde.templateInsert('/templates/inventionsTemplate.json', inventionsTemplate);

fn:QName("http://marklogic.com/xdmp/tde","templateURI") = "/templates/inventionsTemplate.json" fn:QName("http://marklogic.com/xdmp/tde","template") = document{object-node{"template":object-node{"context":text{"patent"}, "directories":array-node{...}, ...}}} fn:QName("http://marklogic.com/xdmp/tde","permissions") = () fn:QName("http://marklogic.com/xdmp/tde","collections") = () fn:QName("http://marklogic.com/xdmp/tde","testvalid") = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>) fn:QName("http://marklogic.com/xdmp/tde","permarray") = json:array() fn:QName("http://marklogic.com/xdmp/tde","colsarray") = json:array()

What is the proper syntax for creating MarkLogic template driven extraction in my case? Am I missing some preparation step before inserting TDE?

CodePudding user response:

Your row is missing a schemaName property.

If you add that to the object in the rows array it will validate and insert.

'rows':[
    {
      'schemaName':'patents',
      'viewName':'inventions',
      'columns':[

The documentation could probably be improved to indicate which properties, such as schemaName and viewName are required and which are optional, such as view-layout.

  • Related