2015-08-18 50 views
3

我嘗試使用函數declareUpdate(); 我複製/粘貼手冊中的代碼,並收到以下錯誤消息。在JavaScript中調用XQuery的declareUpdate在MarkLogic 8中

必須有一些關於這個,我失蹤。我已經添加了,因爲這個錯誤的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; 
+0

您好做了下面的解決方案的工作,因爲我使用PUT功能,而不是後,但我仍然得到相同的錯誤。 – scriobh

+0

對我來說是有效的 – Thijs

回答

2

來電來郵擴展模塊默認得到查詢模式。使用XQuery,您可以將註釋添加到POST函數中以更改該註釋,但ServerSide JavaScript沒有註釋。你最好切換到PUT方法..

HTH!

+0

啊..我記得.. – Thijs