[MarkLogic Dev General] xdmp:document-remove-collections not working

Lanz lancelot.meurillon at gmail.com
Fri Aug 6 08:35:04 PDT 2010


ok Thanks Geert I just try to use different transaction but no change ::
Here is my code

xquery version '1.0-ml';


declare function local:document-del-collection( $targetURI as
xs:string) as empty-sequence()
{
    xdmp:eval("
    xquery version '1.0-ml';
    declare variable $MyTargetURI as xs:string external ;
    xdmp:document-remove-collections($MyTargetURI, ('collection-last'))"
    ,
        (xs:QName("MyTargetURI"), $targetURI) ,
        <options xmlns='xdmp:eval'>
<isolation>different-transaction</isolation>
<prevent-deadlocks>true</prevent-deadlocks>
        </options>  )

};

declare function
local:clean-collection() as empty-sequence()
{
for $doc in fn:collection("collection-last")
return local:document-del-collection(fn:document-uri($doc))
};

declare function
local:document-move($targetURI as xs:string, $sourceURI as xs:string,
$myCollection as xs:string*)
as empty-sequence()
{
    try {
        local:clean-collection(),
        xdmp:document-delete($sourceURI),
        let $permissions := xdmp:document-get-permissions($sourceURI)
        let $collections := $myCollection
        let $quality := xdmp:document-get-quality($sourceURI)
        return
            xdmp:document-insert(
                $targetURI,
                doc($sourceURI),
                if ($permissions)
                    then $permissions
                    else xdmp:default-permissions(),
                if ($collections)
                    then $collections
                    else xdmp:default-collections(),
                $quality ),
        let $prop-ns := namespace-uri(<prop:properties/>)
        let $properties := xdmp:document-properties($sourceURI)/node()
[ namespace-uri(.) ne $prop-ns ]
        return xdmp:document-set-properties($targetURI, $properties)
        }
          catch($e) {
            xdmp:log($e)
        }
};


for $doc in xdmp:directory("/data/items/input/")

    (:retourne les dates de création des fichiers sous la forme YYYY-MM-DD:)
    let $sourceURI := xdmp:node-uri($doc)
    let $myDate := doc($sourceURI)/Items/Item[1]/ExportDate
    let $myYeardate := fn:year-from-date(xs:date($myDate))
    let $targetDir := fn:concat("/data/items/repository/",$myYeardate ,"/")
    let $myShortDate := fn:adjust-date-to-timezone(xs:date($myDate ), ())
    let $targetURI := fn:concat($targetDir,$myShortDate,".xml")
    let $myCollection := ("collection-last",
fn:concat("collection-",$myShortDate),fn:concat("collection-",fn:string-join(fn:tokenize(xs:string($myShortDate),
"-")[1 to 2],"-")),fn:concat("collection-",fn:tokenize(xs:string($myShortDate),
"-")[1]))
order by $myDate
    return local:document-move($targetURI,$sourceURI,$myCollection)


More information about the General mailing list