Skip to content

Instantly share code, notes, and snippets.

@caschwartz
Last active October 11, 2015 13:47
Show Gist options
  • Select an option

  • Save caschwartz/3867861 to your computer and use it in GitHub Desktop.

Select an option

Save caschwartz/3867861 to your computer and use it in GitHub Desktop.
Query two databases, compare URIs, and delete obsolete documents
xquery version "1.0-ml";
let $query := 'cts:uris()'
let $options :=
<options xmlns="xdmp:eval">
<database>{ xdmp:database("my.database") }</database>
</options>
let $theocomURIs := xdmp:eval($query, (), $options)
let $dcwebURIs := cts:uris("/theocom/ia-xml/")[70001 to 80000]
for $dcwebURI in $dcwebURIs
let $uriString := fn:replace($dcwebURI, "/theocom", "")
return
(: The obsolete documents will not match any of the $theocomURIs. :)
if ($uriString = $theocomURIs) then
()
else if (fn:ends-with($uriString, ".xml")) then
xdmp:document-delete(fn:concat("/theocom", $uriString))
else ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment