Marklogic如何更改目录名称

Marklogic How to change directory name

如何在 Marklogic 中将目录从“/Collections/”更新为“/CollectionsCount/”

for $each in xdmp:directory("/collections/", "infinity")
return xdmp:node-uri($each)

result found:
 /collections/Count2017-08-25.xml
 /collections/Count2017-08-27.xml
 /collections/Count2017-08-26.xml
 /collections/Count2017-08-28.xml

我想将目录更新为“/collectionsCount/” 我使用什么功能。提前致谢。

 /collectionsCount/Count2017-08-25.xml
/collectionsCount/Count2017-08-26.xml
....

目录是基于文档 URI 的构造,因此为了更改目录,您需要删除旧文档并在新 URI 处插入新文档(使用新目录前缀代替旧目录前缀).

for $each in xdmp:directory("/collections/", "infinity")
let $old-uri := $each/xdmp:node-uri(.)
let $permissions := xdmp:document-get-permissions($old-uri)
let $collections := xdmp:document-get-collections($old-uri)
let $quality := xdmp:document-get-quality($old-uri)
let $properties := xdmp:document-properties($old-uri)
let $new-uri := concat('/collectionsCount/', substring-after($old-uri, '/collections/'))
return (
  xdmp:document-insert($new-uri, $each, $permissions, $collections, $quality),
  xdmp:document-set-properties($new-uri, $properties),
  xdmp:document-delete($old-uri))

编辑: 已更新以包含@hunterhacker 传播文档元数据的建议。请注意,我故意遗漏了将新文档分配给旧文档的林,因为在大多数情况下我认为让数据库决定更好。