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

如何通过TDE重新运行文档集并返回文档集合?遇XDMP-UNDFUN报错

解决TDE中获取文档集合的报错问题

错误原因

你碰到的XDMP-UNDFUN错误,核心问题有两个:

  1. xdmp:document-get-collections()需要传入文档URI作为参数,但TDE模板<val>中的.代表当前匹配的节点(此处为/match节点),并非文档URI,函数参数不匹配;
  2. 该函数本身不适用于TDE的节点上下文场景,TDE中获取当前节点所属文档的集合,应该用xdmp:node-collections()。

另外,xdmp:node-collections()返回的是字符串序列(若文档属于多个集合),而你定义的doc_collection列scalar-type为string,直接返回序列会导致类型不匹配,需要用string-join()将序列拼接为单个字符串。

修正后的代码

xquery version "1.0-ml";
let $my-first-TDE:=
  <template xmlns="http://marklogic.com/xdmp/tde">
    <context>/match</context>
    <collections>
      <collection>source1</collection>
    </collections>
    <rows>
      <row>
        <schema-name>soccer</schema-name>
        <view-name>matches</view-name>
        <columns>
          <column>
            <name>id</name>
            <scalar-type>long</scalar-type>
            <val>id</val>
          </column>
          <column>
            <name>document</name>
            <scalar-type>string</scalar-type>
            <val>xdmp:node-uri(.)</val>
          </column>
          <column>
            <name>date</name>
            <scalar-type>date</scalar-type>
            <val>match-date</val>
          </column>
          <column>
            <name>league</name>
            <scalar-type>string</scalar-type>
            <val>league</val>
          </column>
          <column>
            <name>doc_collection</name>
            <scalar-type>string</scalar-type>
            <val>string-join(xdmp:node-collections(.), ', ')</val>
            <nullable>true</nullable>
          </column>
        </columns>
      </row>
    </rows>
  </template>
return
  tde:node-data-extract( 
    fn:doc( "/soccer/match/1234567.xml" ), 
    $my-first-TDE 
  )

关键修改说明

  • 替换xdmp:document-get-collections(.)为string-join(xdmp:node-collections(.), ', '):
    • xdmp:node-collections(.)获取当前节点所属文档的所有集合序列
    • string-join()将序列拼接为逗号分隔的字符串,匹配string类型的列定义
  • 修正document列的表达式:原docUri不是有效语法,改用xdmp:node-uri(.)获取当前节点所属文档的URI

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 12:12:28