用JavaScript中的declareUpdate在MarkLogic 8中调用XQuery

时间:2015-08-18 13:41:02

标签: marklogic

我尝试使用函数declareUpdate(); 我复制/粘贴手册中的代码,我收到以下错误消息。

我必须要有一些与此有关的东西。由于此错误,我已添加了declareUpdate:

{error: "XDMP-UPDATEFUNCTIONFROMQUERY: xdmp.apply(create-source#3, "CS_wifi.json", "cswifi", {"getId":{}, "findSource":{}, "createSourceWithMap":{}, "buildSo...}) -- Cannot apply an update function from a query"}  

使用declareUpdate,我得到了这个:

{
  "errorResponse": {
    "statusCode": 400,
    "status": "Bad Request",
    "messageCode": "JS-JAVASCRIPT",
    "message": "JS-JAVASCRIPT: declareUpdate(); -- Error running JavaScript request: Operation not allowed on the currently executing transaction with identifier declareUpdate"
  }
}
/**
 * @name vriendingest 
 * This REST extentsion provides SOAP service for the shipment data
 */

declareUpdate();

var eput   = require("/MarkLogic/rest-api/lib/endpoint-util.xqy");
var link   = require("/ext/obi/lib/link-lib.xqy");
var object = require("/ext/obi/lib/object-service-lib.xqy", "/ext/obi/lib/object-lib.xqy");
var source = require("/ext/obi/lib/source-lib.xqy");

function post(context, params, input) {
    try {
      xdmp.log('title')
      xdmp.log(params.title);

      testing  = source.buildUri('takethisuri');
      title    = params.title;
      dataset  = "cswifi";
      sourceId = source.createSource(title, dataset, source);

      xdmp.log(sourceId);

   response = '{success: "' + testing + '"}';
   }
   catch(err){
      response = '{error: "' + err + '"}';
   }
   context.outputTypes = ["application/xml"];
   context.outputStatus = [200, "OK"];

   return response;
}

// Main
exports.POST = post;

1 个答案:

答案 0 :(得分:2)

默认情况下,POST对分机的调用会获得查询模式。使用XQuery,您可以向POST函数添加注释以更改它,但ServerSide JavaScript没有注释。你最好切换到PUT方法..

HTH!