2017-08-28 1 views
2

ディレクトリ名を変更するディレクトリを更新する方法「/コレクション/」「/ CollectionsCount /」MarklogicMarklogicどのよう

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 
.... 

答えて

4

ディレクトリ文書の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の提案を含めるように更新しました。私は意図的に、古い文書のフォレストに新しい文書を割り当てることをやめました。ほとんどの場合、データベースを決定する方が良いと思われるからです。

+0

ML9の新しいDMSDKは、何千ものURIにヒットした後、qconsoleでタイムアウトになる可能性があるため、このような操作の拡張を容易にします。 GradleでDMSDKを簡単に使用する方法の例については、https://github.com/marklogic-community/ml-gradle/wiki/DMSDK-Tasksを参照してください。 – rjrudin

+3

プロダクションコードは、コレクション、セキュリティ、ドキュメントの品質、プロパティなどのメタデータにもコピーする必要があります。 – hunterhacker

関連する問題