我正在尝试获取连接到特定数据库的所有森林的总大小。

使用下面的代码,我得到了所有单个森林的大小,但是在如何实现该解决方案上心存疑虑:

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

HTH!

关于marklogic - 获取附加到特定数据库的所有林的总大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35765521/

10-13 00:36