将源内容复制到MarkLogic中的另一个数据库后,我们如何从源数据库中删除源内容

发布于 2025-02-13 12:03:41 字数 1114 浏览 1 评论 0原文

我正在使用以下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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惟欲睡 2025-02-20 12:03:41

您需要 catch> catch 发生任何错误或发生任何错误然后继续删除原始文档。

<

...在XDMP中执行更新:eval()或具有不同交易隔离的XDMP-INVOKE(),并在try/Catch块中包装或调用eval或调用。这样,可以捕获提交时间错误。

要实现此更改您的返回:

return
 try {
  let $_ := xdmp:invoke-function(
   function(){ xdmp:document-insert($docuri, $doc, $document-insert-options)},
     $invoke-function-options
   )
  return xdmp:document-delete($docuri)
 }
 catch($exception)
 {
  (: Handle the error :)
  xdmp:rethrow() (: To stop processing and stop the application at this point if desired :) 
 }

在此代码中,如果从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:

...execute the updates in an xdmp:eval() or an xdmp-invoke()with different-transaction isolation, and wrap the eval or invoke inside a try/catch block. In this way, The commit time errors can be caught.

To implement this change your return to:

return
 try {
  let $_ := xdmp:invoke-function(
   function(){ xdmp:document-insert($docuri, $doc, $document-insert-options)},
     $invoke-function-options
   )
  return xdmp:document-delete($docuri)
 }
 catch($exception)
 {
  (: Handle the error :)
  xdmp:rethrow() (: To stop processing and stop the application at this point if desired :) 
 }

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文