You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在MarkLogic中用XQuery获取森林名称、数据目录及特定主机森林列表

MarkLogic 森林信息查询XQuery语句

1. 获取所有森林的名称及其对应数据目录

使用以下XQuery语句可遍历所有森林,返回名称与数据目录路径:

xquery version "1.0-ml";

for $forest in xdmp:forests()
return (
  "森林名称: " || xdmp:forest-name($forest),
  "数据目录: " || xdmp:forest-data-directory($forest),
  "---"
)

xdmp:forests()返回所有森林的ID,通过xdmp:forest-name()提取森林名称,xdmp:forest-data-directory()获取对应的数据目录路径。

2. 查询特定主机/节点下的森林列表及其数据目录

如果需要筛选指定主机上的森林,可结合主机信息做条件过滤:

xquery version "1.0-ml";

let $target-host := "your-host-name"  <!-- 替换为目标主机名 -->
for $forest in xdmp:forests()
let $host-id := xdmp:forest-host($forest)
where xdmp:host-name($host-id) = $target-host
return (
  "森林名称: " || xdmp:forest-name($forest),
  "数据目录: " || xdmp:forest-data-directory($forest),
  "所属主机: " || $target-host,
  "---"
)

将代码中的your-host-name替换为实际主机名称即可。xdmp:forest-host()返回森林所属主机的ID,xdmp:host-name()将ID转换为可读的主机名,通过where子句筛选出目标主机下的森林。

内容的提问来源于stack exchange,提问作者Balan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 05:45:56