Reputation: 139
I'm trying to upload a template to use with MarkLogic Template Driven Extraction. I'm using Javascript in the console (on localhost). However, no matter what I try, I keep getting the same error when I try to upload. The error: "[javascript] SEC-INVALIDPERM: xdmp:document-insert...." I gave myself all the permissions that are possible, but I still keep getting the error.
'use strict'
declareUpdate();
var tde = require("/MarkLogic/tde.xqy");
var MatchesTDE = xdmp.toJSON(
{
"template": {
"context": "/com.marklogic.client.mapper.MatchesDoc",
"collections": ["com.marklogic.client.mapper.MatchesDoc"],
"rows": [
{
"schemaName": "mapper",
"viewName": "matches",
"columns": [
{
"name": "nrOfDocumentsInNC",
"scalarType": "long",
"val": "nrOfDocumentsInNC"
},
{
"name": "totalNrOfDocuments",
"scalarType": "long",
"val": "totalNrOfDocuments"
},
{
"name": "matchesID",
"scalarType": "long",
"val": "matchesID"
},
{
"name": "uniqueInNC",
"scalarType": "boolean",
"val": "uniqueInNC"
}
]
}
]
}
}
);
tde.templateInsert(
"/MatchesDoc/TDE.json" ,
MatchesTDE,
xdmp.defaultPermissions(),
["com.marklogic.client.autorelationmapper.MatchesDoc"]
);
By the way, if I validate the template with tde.validate([MatchesTDE]);
I get true
. And if I test the script with
tde.nodeDataExtract(
[cts.doc( "com.marklogic.client.mapper.MatchesDoc/2722286.json" )],
[MatchesTDE]
);
it works. Moreover, when I follow the tutorial on TDE at https://developer.marklogic.com/learn/template-driven-extraction everything works except the insertTemplate function. I also get the same error there. What am I doing wrong?
Upvotes: 0
Views: 202
Reputation: 2679
Try removing all the permissions for the user running this code. Or try running the tde.templateInsert()
with an empty 3rd argument:
tde.templateInsert(
"/MatchesDoc/TDE.json" ,
MatchesTDE,
[],
["com.marklogic.client.autorelationmapper.MatchesDoc"]
);
It sounds like this is your problem:
I gave myself all the permissions that are possible, but I still keep getting the error.
Users don't have permissions, documents have permissions. Users only have default permissions for when they write documents.
A user's default permissions are the set of permissions that get assigned to a document that the user inserts. Default permissions do not grant that user any additional powers in the database. Normally, an admin user has no default permissions assigned to it.
When you assign all those default permissions to your user, you end up adding a huge list of permissions in the 3rd argument of tde.templateInsert()
where you pass xdmp.defaultPermissions()
. At least one of those is somehow invalid, so you're getting the SEC-INVALIDPERM error.
Upvotes: 1