根据原始目录结构动态设置集合名称
Setting collection name dynamically based on original directory structure
我想动态添加原始目录名作为
加载文件时收集。
假设有以下文件:/home/sampledata/dir1/targetfile.xml
我希望 targetfile.xml 包含在以下集合中:
"home"、"sampledata"、"dir1"
我们可以在通过 MLCP 导入时执行此操作吗?
或者如果有人可以分享通过脚本实现的替代方法,我们将不胜感激。
我建议使用 MLCP 转换。它最常用于在插入前操作内容,但您也可以使用它调整 uri、集合等。
有关 MLCP 变换的一般详细信息,请参阅:https://docs.marklogic.com/guide/mlcp/import#id_82518
有关转换输出选项的更多具体细节,请参阅:https://docs.marklogic.com/guide/mlcp/import#id_59764
HTH!
您可以使用此查询:
let $dir-seprator := "/"
for $uri in cts:uri-match("*")[fn:ends-with(.,'.xml')][1 to 10]
let $collection := fn:substring-before($uri,fn:tokenize($uri,$dir-seprator)[fn:last()])
return
xdmp:document-set-collections($uri,fn:tokenize($collection,$dir-seprator)[.!='']))
我想动态添加原始目录名作为 加载文件时收集。
假设有以下文件:/home/sampledata/dir1/targetfile.xml 我希望 targetfile.xml 包含在以下集合中: "home"、"sampledata"、"dir1"
我们可以在通过 MLCP 导入时执行此操作吗? 或者如果有人可以分享通过脚本实现的替代方法,我们将不胜感激。
我建议使用 MLCP 转换。它最常用于在插入前操作内容,但您也可以使用它调整 uri、集合等。
有关 MLCP 变换的一般详细信息,请参阅:https://docs.marklogic.com/guide/mlcp/import#id_82518
有关转换输出选项的更多具体细节,请参阅:https://docs.marklogic.com/guide/mlcp/import#id_59764
HTH!
您可以使用此查询:
let $dir-seprator := "/"
for $uri in cts:uri-match("*")[fn:ends-with(.,'.xml')][1 to 10]
let $collection := fn:substring-before($uri,fn:tokenize($uri,$dir-seprator)[fn:last()])
return
xdmp:document-set-collections($uri,fn:tokenize($collection,$dir-seprator)[.!='']))