将源内容复制到MarkLogic中的另一个数据库后,我们如何从源数据库中删除源内容
我正在使用以下Xquery将文档从一个数据库复制到Marklogic中的另一个数据库。 除了复制我的要求外,还要删除成功复制的那些文档。 我无法完全删除该集合,因为某些文档可能不会复制,因为由于模板文档错误,这些文档未能复制。
是否有一种方法可以获取由于模板错误而未被复制和失败的文档列表,并将其保留在源数据库中并删除其余部分。
这是我复制文档的Xquery-
xquery version "1.0-ml";
for $doc in cts:search(doc(), cts:collection-query('Collection1'))
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>{
<collection>{$collections}</collection>
}
</collections>
</options>
let $db-name := "STAGING"
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
);
I am using below xquery to copy documents from one database to another in MarkLogic.
Along with copying my requirement is to remove those documents which are successfully copied.
I cannot remove the collection fully as some of the documents may not get copied as they fails to get copied due to template document errors which are present in the target database.
Is there a way to get the list of the documents which are not copied and got failed due to template errors and retain them in the source database and delete the rest of them.
Here is my xquery to copy the documents -
xquery version "1.0-ml";
for $doc in cts:search(doc(), cts:collection-query('Collection1'))
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>{
<collection>{$collections}</collection>
}
</collections>
</options>
let $db-name := "STAGING"
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
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要 catch> catch 发生任何错误或发生任何错误然后继续删除原始文档。
<
要实现此更改您的返回:
在此代码中,如果从Invoke-unction抛出异常,则文档 - 删除将无法运行。相反,执行将跳入捕获块。
另一种方法是在单独的操作中执行删除。您可以从数据库2中获取URI的列表,然后删除数据库1中存在的任何内容。
第二种替代方法是使用数据库复制复制数据,然后一旦完全复制,然后删除原始数据库。
第三种替代方法是使用备份复制数据,然后删除原始数据库。
You need to catch any error that occurs and handle it or if no error occurs then proceed with deleting the original document.
The KnowledgeBase suggests:
To implement this change your return to:
In this code the document-delete won't run if an exception is thrown from invoke-function. Instead, execution will jump into the catch block.
An alternative approach is to do the deletes in a separate operation. You could get a list of URIs from Database 2 and then delete anything in that list that exists in Database 1.
A second alternative approach is to copy the data over using database replication and then deleting the original database once fully replicated.
A third alternative approach is to copy the data over using a backup and then deleting the original database.