Marklogic 获取附加到特定数据库的所有林的总大小

Marklogic 获取附加到特定数据库的所有林的总大小,marklogic,Marklogic,我试图得到所有森林的总大小,这些森林都连接到一个特定的数据库 使用下面的代码,我得到了所有单个林的大小,但仍停留在如何实现解决方案上: for $db-id in xdmp:databases() let $db-name := xdmp:database-name($db-id) for $forests in xdmp:forest-status(xdmp:database-forests(xdmp:database($db-name))) let $space := $forests//f

我试图得到所有森林的总大小,这些森林都连接到一个特定的数据库

使用下面的代码,我得到了所有单个林的大小,但仍停留在如何实现解决方案上:

for $db-id in xdmp:databases()
let $db-name := xdmp:database-name($db-id)
for $forests in xdmp:forest-status(xdmp:database-forests(xdmp:database($db-name)))
let $space := $forests//forest:device-space
let $f_name := $forests//forest:forest-name
for $stand in $forests//forest:stands
let $f_size := fn:sum($stand/forest:stand/forest:disk-size)

我认为您正在寻找类似于:

xquery version "1.0-ml";

declare namespace forest = "http://marklogic.com/xdmp/status/forest";

for $db-id in xdmp:databases()
let $db-name := xdmp:database-name($db-id)
let $db-size :=
  fn:sum(
    for $f-id in xdmp:database-forests($db-id)
    let $f-status := xdmp:forest-status($f-id)
    let $space := $f-status/forest:device-space
    let $f-name := $f-status/forest:forest-name
    let $f-size :=
      fn:sum(
        for $stand in $f-status/forest:stands/forest:stand
        let $stand-size := $stand/forest:disk-size/fn:data(.)
        return $stand-size
      )
    return $f-size
  )
order by $db-size descending
return $db-name || " = " || $db-size

最好使用一系列林ID进行调用,而不是进行一系列单独的调用,以便并行完成工作

xquery version "1.0-ml";

declare namespace fs = "http://marklogic.com/xdmp/status/forest";

let $include-replicas := fn:true()
let $db := xdmp:database("MyDatabase")
for $fs in xdmp:forest-status(xdmp:database-forests($db, $include-replicas))
return
  fn:string-join(
    ( $fs/fs:forest-name, fn:sum($fs/fs:stands/fs:stand/fs:disk-size) ) ! fn:string(.),
    " ")