marklogic 在阵列上创建实例错误 - javascript
marklogic create instance error out on array - javascript
[javascript] XDMP-CAST: (err:FORG0001) xs:string#1(.) -- Invalid cast: `json:object(<json:object xmlns:xs="http://www.w3.org/2001/XMLSchema" `
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>) cast as xs:string
Stack Trace
In /MarkLogic/entity-services/entity-services.xqy on line 313
In xs:string#1(.)
fn:QName("http://marklogic.com/entity-services","source-nodes") =
fn:doc("/budget/Accomplishments/objective/2019-6.json")/array-node("tasks")/object-node()
fn:QName("http://marklogic.com/entity-services","fn") = xs:string#1`
declareUpdate();
const es = require('/MarkLogic/entity-services/entity-services.xqy');
const Completed = require('/es-gs/CompletedObjectiveEntity-1.0.0-conv.xqy');
for (const source of fn.collection('Objective,Accomplishments')) {
let instance = Completed['extract-instance-CompletedObjectives'](source);
let uri = '/es-gs/env/'+ instance.id + '.json';
xdmp.documentInsert(
uri, Completed.instanceToEnvelope(instance, "json"),
{collections: ['CompletedObjective-envelopes']}
);}
我正在尝试创建实例文档,但在线出错
let $tasks := es:extract-array($source-node/tasks, xs:string#1)
我不确定为什么会出错
样本
{
"goal": "- Launched",
"tasks": [
{
"Task-1": "-- Step 1"
},
{
"Task-2": "-- Step 22"
},
{
"Task-3": "-- Step 33"
}
],
"id": "1"
}
这里是关于任务的更多代码
我有以下代码的备选服务器。它构建并部署了实例,但数组中没有任务
MarkLogic 将像这样行走和处理您的树:
/array-node()/object-node()/array-node()/text()[#], …
下面的自定义模块使用MarkLogic Entity Services
:
将数组转换为规范模型
Within the instance data extract function, please replace your code
let $tasks := es:extract-array($source-node/tasks, xs:string#1)
with my codes (works for 0..1
, 1..1
, 1..*
)
==================================================================
let $Tasks := $source-node/tasks[1 to fn:last()]
==================================================================
=>es:optional('Tasks', array-node{$Tasks})
};
harmonised and enveloped document
{
"envelope": {
"instance": {
"info": {
"title": "CompletedObjective",
"version": "1.0"
},
"CompletedObjective": {
"objectiveID": "1",
"objectiveGoal": "- Launched",
"Tasks": [
{
"Task-1": "-- Step 1"
},
{
"Task-2": "-- Step 22"
},
{
"Task-3": "-- Step 33"
}
]
}
},
"attachments": [
{
"goal": "- Launched",
"tasks":
[
=======================
NOTE: You can also leverage MarkLogic Data Hub Framework to facilitate data modelling.
[javascript] XDMP-CAST: (err:FORG0001) xs:string#1(.) -- Invalid cast: `json:object(<json:object xmlns:xs="http://www.w3.org/2001/XMLSchema" `
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>) cast as xs:string
Stack Trace
In /MarkLogic/entity-services/entity-services.xqy on line 313
In xs:string#1(.)
fn:QName("http://marklogic.com/entity-services","source-nodes") =
fn:doc("/budget/Accomplishments/objective/2019-6.json")/array-node("tasks")/object-node()
fn:QName("http://marklogic.com/entity-services","fn") = xs:string#1`
declareUpdate();
const es = require('/MarkLogic/entity-services/entity-services.xqy');
const Completed = require('/es-gs/CompletedObjectiveEntity-1.0.0-conv.xqy');
for (const source of fn.collection('Objective,Accomplishments')) {
let instance = Completed['extract-instance-CompletedObjectives'](source);
let uri = '/es-gs/env/'+ instance.id + '.json';
xdmp.documentInsert(
uri, Completed.instanceToEnvelope(instance, "json"),
{collections: ['CompletedObjective-envelopes']}
);}
我正在尝试创建实例文档,但在线出错
let $tasks := es:extract-array($source-node/tasks, xs:string#1)
我不确定为什么会出错
样本
{
"goal": "- Launched",
"tasks": [
{
"Task-1": "-- Step 1"
},
{
"Task-2": "-- Step 22"
},
{
"Task-3": "-- Step 33"
}
],
"id": "1"
}
这里是关于任务的更多代码
我有以下代码的备选服务器。它构建并部署了实例,但数组中没有任务
MarkLogic 将像这样行走和处理您的树:
/array-node()/object-node()/array-node()/text()[#], …
下面的自定义模块使用MarkLogic Entity Services
:
Within the instance data extract function, please replace your code
let $tasks := es:extract-array($source-node/tasks, xs:string#1)
with my codes (works for
0..1
,1..1
,1..*
)
==================================================================
let $Tasks := $source-node/tasks[1 to fn:last()]
==================================================================
=>es:optional('Tasks', array-node{$Tasks})
};
harmonised and enveloped document
{
"envelope": {
"instance": {
"info": {
"title": "CompletedObjective",
"version": "1.0"
},
"CompletedObjective": {
"objectiveID": "1",
"objectiveGoal": "- Launched",
"Tasks": [
{
"Task-1": "-- Step 1"
},
{
"Task-2": "-- Step 22"
},
{
"Task-3": "-- Step 33"
}
]
}
},
"attachments": [
{
"goal": "- Launched",
"tasks":
[
=======================
NOTE: You can also leverage MarkLogic Data Hub Framework to facilitate data modelling.