Reputation: 1147
How to update directory from "/Collections/" to "/CollectionsCount/" in Marklogic
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
I would like to update directory to become "/collectionsCount/" what function do I use. Thanks in advance.
/collectionsCount/Count2017-08-25.xml
/collectionsCount/Count2017-08-26.xml
....
Upvotes: 2
Views: 224
Reputation: 11771
Directories are a construct based on a document's URI, so in order to change the directories, you will need to delete the old documents and insert new ones at new URIs (using the new directory prefix in place of the old one).
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))
Edit: Updated to include @hunterhacker's suggestion to propagate document metadata. Note that I intentionally left out assigning the new document to the old document's forest, since in most cases I assume it's better to let the database decide.
Upvotes: 4