这是我以前遇到过很多次的问题。在将数据加载到MarkLogic时,我无法控制类型。
source.createSource函数需要:
$title as xs:string,
$dataset as xs:string?,
$content as document-node()*
typeof(输入)显示它是一个对象。所以我需要从这个对象转到文档节点。
数据
{ "id": "123",
"something": "yes"
}
错误
2015-08-19 09:26:35.150 Info:vriend:Status 500:JS-JAVASCRIPT:sourceId = source.createSource(title,dataset,source); - 运行JavaScript请求时出错:TypeError:undefined不是函数
脚本
/**
* @name vriendingest
* This REST extension 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 put(context, params, input) {
xdmp.log('input ' + typeof(input));
var data = input.toObject();
xdmp.log('data ' + typeof(data));
xdmp.log(data.length);
testing = source.buildUri('takethisuri');
title = 'test';
source = data;
dataset = "cswifi";
sourceId = source.createSource(title, dataset, source);
xdmp.log(sourceId);
response = '{success: "or something"}';
context.outputTypes = ["application/xml"];
context.outputStatus = [200, "OK"];
return response;
}
// Main
exports.PUT = put;
答案 0 :(得分:1)
我认为这一行隐藏了您之前对source
的定义:
source = data;
我建议将var
放在应该是函数本地的变量前面。使用带有这些额外变量的JSHint验证代码,并且在函数内部使用'use strict';
告诉我source
正在重新定义。我不认为你想要隐藏source-lib的需求和数据的值..
HTH!