function get(context, params) {
var max = "http://blahblah"; //declaring namespace
let query = []
if (params.tokenNum) {
query.push(cts.elementValueQuery(fn.QName(max, "TOKENUM"), params.tokenNum))
query.push(cts.collectionQuery("WORKORDER"))
}
if (params.location) {
query.push(cts.elementValueQuery(fn.QName(max, "LOC"), params.location))
query.push(cts.collectionQuery("WORKORDER"))
}
if (params.Id) {
query.push(cts.elementValueQuery(fn.QName(max, "ID"), params.Id))
query.push(cts.collectionQuery("WORKORDER"))
}
let result = []
let doc = fn.subsequence(cts.search(cts.andQuery(query)), params.start, params.length)
const json = require('/MarkLogic/json/json.xqy');
let config = json.config("custom");
for (var d of doc) {
result.push(json.transformToJson(d, config));
}
return result
};
我正在尝试使用REST扩展名返回JSON文档数组,但我得到的只是一个空数组,我正在使用URL http://localhost:9015/v1/resources/location?rs:Id=ABC&rs:start=1&rs:length=10
但是,当我通过使用params对象作为这样的测试在查询控制台中运行此代码时
let params = {
start: '1',
length: '10',
tokenNum: "100404",
location: "0256",
Id: "ABC"
};
然后我得到了我想要的东西(这是JSON文档的数组)。
我不知道出了什么问题。如果有人可以提供帮助,我将不胜感激