将文档从一个数据库复制到MarkLogic -XDMP:Document -insert失败
我正在使用以下代码将文档从一个数据库复制到MarkLogic中的另一个数据库。 但是我遇到了错误-ARG2不为type node() 我正在尝试的Xquery-
xquery version "1.0-ml";
for $doc in cts:search(doc(), cts:collection-query('Shipment'))
let $docuri := $doc/base-uri()
let $collections := xdmp:document-get-collections($docuri)
let $permissions := xdmp:document-get-permissions($docuri)
let $db-name := "GTM2_FINAL"
return
xdmp:invoke-function(function()
{
xdmp:document-insert
(
$docuri, $docuri,
<options xmlns="xdmp:document-insert" xmlns1="xdmp:eval">
<permissions>{xdmp:default-permissions()}</permissions>
<collections>
{
<collection>GTM2_Shipment</collection>,
<collection>Shipment</collection>
}
</collections>
<database>{ xdmp:database("GTM2_TEST") }</database>
<commit>auto</commit>
</options>
)
}
);
这是我遇到的错误 -
[1.0-ml] XDMP-ARGTYPE: (err:XPTY0004) xdmp:document-insert(xs:anyURI("/shipment/test..."), xs:anyURI("/shipment/test..."), <options xmlns1="xdmp:eval" xmlns="xdmp:document-insert"><permissions>...</permissions>...</options>) -- arg2 is not of type node()
I am using the below code to copy documents from one database to another database in MarkLogic.
But I am getting error - arg2 is not of type node()
The xquery I am trying -
xquery version "1.0-ml";
for $doc in cts:search(doc(), cts:collection-query('Shipment'))
let $docuri := $doc/base-uri()
let $collections := xdmp:document-get-collections($docuri)
let $permissions := xdmp:document-get-permissions($docuri)
let $db-name := "GTM2_FINAL"
return
xdmp:invoke-function(function()
{
xdmp:document-insert
(
$docuri, $docuri,
<options xmlns="xdmp:document-insert" xmlns1="xdmp:eval">
<permissions>{xdmp:default-permissions()}</permissions>
<collections>
{
<collection>GTM2_Shipment</collection>,
<collection>Shipment</collection>
}
</collections>
<database>{ xdmp:database("GTM2_TEST") }</database>
<commit>auto</commit>
</options>
)
}
);
Here is the error I am getting -
[1.0-ml] XDMP-ARGTYPE: (err:XPTY0004) xdmp:document-insert(xs:anyURI("/shipment/test..."), xs:anyURI("/shipment/test..."), <options xmlns1="xdmp:eval" xmlns="xdmp:document-insert"><permissions>...</permissions>...</options>) -- arg2 is not of type node()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码有几个问题,但是第一个问题以及错误消息告诉您的内容是,
XDMP的第二个参数:document-insert()
不是节点。您指定$ docuri
,它是文档URI的字符串值。第二个参数应为$ doc
。我看到的另一个问题是,您将
XDMP的参数混合在一起:document-insert()
函数与XDMP的选项参数:Invoke-function()
。需要指定两个不同的选项参数,并且元素与两个不同的名称空间绑定。XDMP的选项参数:document-insert()
应该是:或者,如果要使用文档的权限和集合:
xdmp的选项参数:Invoke-unction( )
是:如果您不想使用文档中的集合或权限,则无需获取它们。我在先前答案中提供的答案显示了一种将它们与
XDMP的较旧API一起使用的方法:docuct-insert()
将使用集合和权限用作特定参数而不是在选项参数中。您将变量
$ db-name
带有“ gtm2_final”的值,但不要使用它,而是对eval选项中的值进行了硬编码。要么使用变量代替字符串,要么摆脱未使用的变量。应用更改:
如果它使其更容易,您还可以
让
为选项命名变量,以使读取和保持实际函数调用更易于:A couple of issues with your code, but the first one and what the error message is telling you, is that the second parameter for
xdmp:document-insert()
is not a node. You specified$docuri
, which is a string value of the URI of the document. The second parameter should instead be$doc
.The other issue I see is that you have mixed the parameters for the
xdmp:document-insert()
function with the options parameter for thexdmp:invoke-function()
. Two different options params need to be specified, and the elements are bound to two different namespaces.The options parameter for the
xdmp:document-insert()
should be:Or if you want to use the permissions and collections of the document:
The options parameter for the
xdmp:invoke-function()
are:And if you don't want to use the collections or permissions from the document, then no need to fetch them. The answer that I provided in previous answers showed a way to use them with the older API for
xdmp:document-insert()
that used collections and permissions as specific parameters, rather than within the options parameter.You let a variable
$db-name
with the value "GTM2_FINAL", but don't use it and instead have hard-coded the value in the eval option. Either use the variable instead of the string, or get rid of the unused variable.Applying the changes:
If it makes it easier, you could also
let
named variables for the options, to make it easier to read and keep the actual function calls shorter: