Skip to content

Instantly share code, notes, and snippets.

@ableasdale
Created June 11, 2019 18:54
Show Gist options
  • Save ableasdale/10d5d4bf57ca7ec8611ecb50ab4f90b0 to your computer and use it in GitHub Desktop.
Save ableasdale/10d5d4bf57ca7ec8611ecb50ab4f90b0 to your computer and use it in GitHub Desktop.
MarkLogic: for a support dump, list the host id and all forest names associated with that host
xquery version "1.0-ml";
(:
: Get the host/forest configuration
:)
declare default element namespace "http://marklogic.com/xdmp/status/forest";
declare variable $path as xs:string := '/Users/ableasdale/Downloads/SuppDump20190414';
declare variable $support as document-node()* := xdmp:document-get (
$path,
<options xmlns="xdmp:document-get">
<format>xml</format>
<repair>full</repair>
</options>
);
declare variable $fs := $support/forest-status;
declare function local:get-host-ids() {
fn:distinct-values(for $forest in $fs
return fn:data($forest/host-id))
};
declare function local:get-forests-by-host($id) {
for $forest in $fs where fn:data($forest/host-id) eq $id order by fn:data($forest/forest-name) return (" - "||fn:data($forest/forest-name))
};
for $host in local:get-host-ids() return ($host, local:get-forests-by-host($host))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment