尝试抓住Xquery不工作的Marklogic
我正在使用以下代码将与指定集合有关的文档从一个数据库复制到另一个数据库。 在我的尝试块中,我将在成功复制后返回以删除所有文档。在捕获中只是为了打印例外。 但这给了我一个我无法弄清楚的语法错误。有人可以帮我吗?
xquery version "1.0-ml";
for $doc in cts:search(doc(), cts:collection-query('Test'))
let $docuri := $doc/base-uri()
let $collections := xdmp:document-get-collections($docuri)
let $permissions := xdmp:document-get-permissions($docuri)
let $document-insert-options :=
<options xmlns="xdmp:document-insert">
<permissions>{$permissions}</permissions>z
<collections>{
<collection>{$collections}</collection>
}
</collections>
</options>
let $db-name := "Final"
let $invoke-function-options :=
<options xmlns="xdmp:eval">
<database>{ xdmp:database($db-name) }</database>
<commit>auto</commit>
</options>
return
try {
xdmp:invoke-function(
function(){ xdmp:document-insert($docuri, $doc, $document-insert-options)},
$invoke-function-options
);
return xdmp:document-delete($doc)
}
catch ($exception) {
"Problem loading file, received the following exception: ",
$exception }
I am using below code to copy documents related to specified collection from one database to another database.
In my try block I am returning to delete all the documents after successful copy. And in the catch just to print the exception .
But it gives me a syntax error which I am not able to figure out. Can someone please help me in this -
xquery version "1.0-ml";
for $doc in cts:search(doc(), cts:collection-query('Test'))
let $docuri := $doc/base-uri()
let $collections := xdmp:document-get-collections($docuri)
let $permissions := xdmp:document-get-permissions($docuri)
let $document-insert-options :=
<options xmlns="xdmp:document-insert">
<permissions>{$permissions}</permissions>z
<collections>{
<collection>{$collections}</collection>
}
</collections>
</options>
let $db-name := "Final"
let $invoke-function-options :=
<options xmlns="xdmp:eval">
<database>{ xdmp:database($db-name) }</database>
<commit>auto</commit>
</options>
return
try {
xdmp:invoke-function(
function(){ xdmp:document-insert($docuri, $doc, $document-insert-options)},
$invoke-function-options
);
return xdmp:document-delete($doc)
}
catch ($exception) {
"Problem loading file, received the following exception: ",
$exception }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
迈克尔和罗布都有好积分,但还有一些问题。
MarkLogic确实抱怨$ document-insert-options中的额外“ z”。摆脱这一点。
MarkLogic还将抱怨您将您传递给$ doc而不是$ docuri的事实:xdmp:document-delete。因此,也改变了这一点。
最后是半颜料。 Marklogic确实支持了这一点,但仅在顶级。使用Michael建议,插入和删除可能并行发生。使用Rob提出的额外的“让$ _:=',然后删除';'将导致Marklogic首先插入,然后删除第二。我认为这就是您所追求的。
从QC('Fab'会做的)对随机数据库进行以下操作,在我的末端正常工作:
HTH!
Michael and Rob both have good points, but there are a few more issues.
MarkLogic does complain about the extra 'z' in the $document-insert-options. Get rid of that.
MarkLogic will also complain about the fact you are passing in $doc instead of $docuri into xdmp:document-delete. So change that as well.
Last is the semi-colon bit. MarkLogic does support that, but only on top-level. Using Michael suggestion, insert and delete might happen in parallel. Using Rob's suggestion of an extra 'let $_ :=', and removing ';' will cause MarkLogic to first insert, and delete second. I think that is what you are after.
Running the following against a random database from QC ('Fab' will do), works fine on my end:
HTH!
什么是错误?
此块看起来错误:
您有一个
z
在&lt;/permissions&gt;
之后浮出水面,这可能会破坏选项节点的架构验证。这也可能是错误的:
您可能需要明确返回这样的序列:
这对我来说似乎也很奇怪:
通过尝试使用
>;
的多态交易来打破flwor。而是尝试:
What is the error?
Offhand this block looks wrong:
You have a
z
floating out there after</permissions>
which could be breaking schema validation of the options node.This also could be wrong:
You may need to explicitly return a Sequence like so:
This also seems odd to me:
This breaks FLWOR by trying to use a multi-statement transaction with the
;
.Instead try:
Xquery没有分号限制的语句,也没有任何以“返回”开头的指令或表达式。
用逗号(
“,”
)替换“; return”
。Marklogic也可能有特殊的规则来调用具有副作用的功能;我不知道那个领域。
XQuery doesn't have semicolon-delimited statements, nor does it have any instruction or expression that starts with the keyword "return".
Replace the
"; return"
by a comma (","
).Marklogic may also have special rules for invoking functions with side-effects; I wouldn't know about that area.