Search code examples
transactionsxquerymarklogic

Content ingestion and properties update using marklogic dls API in same transaction


import module namespace dls = "http://marklogic.com/xdmp/dls" at "/MarkLogic/dls.xqy";

let $uri := "/ml-workflow/test2.xml" 

let $content := <apple>APPLE</apple>

let $properties := <prop>MANGO</prop>

return

(dls:document-insert-and-manage($uri,fn:false(),$content),dls:document-set-properties($uri,$properties) )

Question: I am trying to insert a document and set its properties using Marklogic dls API in the same transaction, but it is not allowing me to do so. Kindly help!


Solution

  • This is explained with code samples at http://blakeley.com/blogofile/2013/06/21/introduction-to-multi-statement-transactions/

    Try something like this:

    import module namespace dls = "http://marklogic.com/xdmp/dls"
      at "/MarkLogic/dls.xqy";
    
    declare option xdmp:transaction-mode "update";
    
    let $uri := "/ml-workflow/test2.xml" 
    let $content := <apple>APPLE</apple>
    return dls:document-insert-and-manage($uri,fn:false(),$content)
    ;
    
    import module namespace dls = "http://marklogic.com/xdmp/dls"
      at "/MarkLogic/dls.xqy";
    
    let $uri := "/ml-workflow/test2.xml" 
    let $properties := <prop>MANGO</prop>
    return dls:document-set-properties($uri,$properties)
    xdmp:commit()
    

    If you use external variables you can avoid the repeated values.