[英]Copy documents from one database to another in MarkLogic - xdmp:document-insert Failing
I am using the below code to copy documents from one database to another database in MarkLogic.我正在使用以下代码将文档从一个数据库复制到 MarkLogic 中的另一个数据库。 But I am getting error - arg2 is not of type node() The xquery I am trying -
但我收到错误 - arg2 不是 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>
)
}
);
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()
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.您的代码有几个问题,但第一个问题和错误消息告诉您的是
xdmp:document-insert()
的第二个参数不是节点。 You specified $docuri
, which is a string value of the URI of the document.您指定
$docuri
,它是文档 URI 的字符串值。 The second parameter should instead be $doc
.第二个参数应该是
$doc
。
The other issue I see is that you have mixed the parameters for the xdmp:document-insert()
function with the options parameter for the xdmp:invoke-function()
.我看到的另一个问题是您将
xdmp:document-insert()
函数的参数与xdmp:invoke-function()
的 options 参数混合在一起。 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: xdmp:document-insert()
的选项参数应该是:
<options xmlns="xdmp:document-insert">
<permissions>{xdmp:default-permissions()}</permissions>
<collections>
<collection>GTM2_Shipment</collection>
<collection>Shipment</collection>
</collections>
</options>
Or if you want to use the permissions and collections of the document:或者如果你想使用文档的权限和集合:
<options xmlns="xdmp:document-insert">
<permissions>{$permissions}</permissions>
<collections>{$collections}</collections>
</options>
The options parameter for the xdmp:invoke-function()
are: xdmp:invoke-function()
的选项参数是:
<options xmlns="xdmp:eval">
<database>{ xdmp:database("GTM2_TEST") }</database>
<commit>auto</commit>
</options>
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.我在之前的答案中提供的答案显示了一种将它们与用于
xdmp:document-insert()
的旧 API 一起使用的方法,该 API 使用集合和权限作为特定参数,而不是在 options 参数中。
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.您让变量
$db-name
的值为“GTM2_FINAL”,但不要使用它,而是在 eval 选项中硬编码该值。 Either use the variable instead of the string, or get rid of the unused variable.要么使用变量而不是字符串,要么去掉未使用的变量。
Applying the changes:应用更改:
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, $doc,
<options xmlns="xdmp:document-insert">
<permissions>{$permissions}</permissions>
<collections>{$collections}</collections>
</options>
)
},
<options xmlns="xdmp:eval">
<database>{ xdmp:database($db-name) }</database>
<commit>auto</commit>
</options>
);
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:如果它更容易,
let
还可以为选项设置命名变量,以使其更易于阅读并保持实际函数调用更短:
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 $document-insert-options :=
<options xmlns="xdmp:document-insert">
<permissions>{$permissions}</permissions>
<collections>{$collections}</collections>
</options>
let $db-name := "GTM2_FINAL"
let $invoke-function-options :=
<options xmlns="xdmp:eval">
<database>{ xdmp:database($db-name) }</database>
<commit>auto</commit>
</options>
return
xdmp:invoke-function(
function(){ xdmp:document-insert($docuri, $doc, $document-insert-options)},
$invoke-function-options
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.