我们如何在单个 XQuery 代码中获取所有 MarkLogic 数据库文档计数?
How we can get all MarkLogic databases document counts in single XQuery Code?
我们需要使用 XQuery 生成报告,其中我们需要数据库大小和数据库文档计数(总文档值)等详细信息。
我们有下面的 XQuery 代码,我们可以从中获取数据库名称和数据库大小,但我们还想包括 AdminUI 中的数据库文档计数。
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 $space
)
return $f-size
)
order by $db-size descending
return $db-name || " = " || $db-size
类似
return $db-name || " = " || $db-size || "=" || $db-count
使用下面的方法,我们可以在单个数据库中获取文档计数(无论在 QC 下拉列表中选择什么),但我需要 运行 在单个脚本中对所有数据库执行以下命令。
xdmp:estimate(doc())
对此有什么帮助或建议吗?提前感谢您的帮助。
您可以使用 xdmp:forest-counts()
检索 document-count
并将它们相加,就像您对大小所做的那样:
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 $space
)
return $f-size
)
let $db-count :=
fn:sum(
for $forest-id in xdmp:database-forests($db-id)
let $forest-counts := xdmp:forest-counts($forest-id)
return $forest-counts/forest:document-count/fn:data(.)
)
order by $db-size descending
return $db-name || " = " || $db-size || ", " || $db-count
如果你确实想使用 xdmp:estimate(doc())
那么你可以使用 xdmp:invoke-function()
并在选项中指定要执行的内容 database
:
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 $space
)
return $f-size
)
let $db-count :=
xdmp:invoke-function(
function(){ xdmp:estimate(doc())},
<options xmlns="xdmp:eval">
<database>{$db-id}</database>
</options>)
order by $db-size descending
return $db-name || " = " || $db-size || ", " || $db-count
我们需要使用 XQuery 生成报告,其中我们需要数据库大小和数据库文档计数(总文档值)等详细信息。
我们有下面的 XQuery 代码,我们可以从中获取数据库名称和数据库大小,但我们还想包括 AdminUI 中的数据库文档计数。
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 $space
)
return $f-size
)
order by $db-size descending
return $db-name || " = " || $db-size
类似
return $db-name || " = " || $db-size || "=" || $db-count
使用下面的方法,我们可以在单个数据库中获取文档计数(无论在 QC 下拉列表中选择什么),但我需要 运行 在单个脚本中对所有数据库执行以下命令。
xdmp:estimate(doc())
对此有什么帮助或建议吗?提前感谢您的帮助。
您可以使用 xdmp:forest-counts()
检索 document-count
并将它们相加,就像您对大小所做的那样:
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 $space
)
return $f-size
)
let $db-count :=
fn:sum(
for $forest-id in xdmp:database-forests($db-id)
let $forest-counts := xdmp:forest-counts($forest-id)
return $forest-counts/forest:document-count/fn:data(.)
)
order by $db-size descending
return $db-name || " = " || $db-size || ", " || $db-count
如果你确实想使用 xdmp:estimate(doc())
那么你可以使用 xdmp:invoke-function()
并在选项中指定要执行的内容 database
:
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 $space
)
return $f-size
)
let $db-count :=
xdmp:invoke-function(
function(){ xdmp:estimate(doc())},
<options xmlns="xdmp:eval">
<database>{$db-id}</database>
</options>)
order by $db-size descending
return $db-name || " = " || $db-size || ", " || $db-count