我發現你必須使用xdmp:eval()函數在不同的事務中運行這些命令中的每一個。執行以下操作將起作用。
let $deleteCommand := "declare variable $directory as xs:string external; xdmp:directory-delete($directory)"
let $createCommand := "declare variable $directory as xs:string external; xdmp:directory-create($directory)"
let $_ := xdmp:eval($deleteCommand, (xs:QName("directory"), $directory),<options xmlns="xdmp:eval"><isolation>different-transaction</isolation><prevent-deadlocks>false</prevent-deadlocks></options>)
let $_ := xdmp:eval($createCommand, (xs:QName("directory"), $directory),<options xmlns="xdmp:eval"><isolation>different-transaction</isolation><prevent-deadlocks>false</prevent-deadlocks></options>)
return $_
在eval中運行其中一個命令並調用另一個命令不起作用,因爲這會產生死鎖。
儘管有這個答案,我仍然對刪除目錄內容的解決方案感興趣,如果任何人有一個。
http://docs.marklogic.com/guide/app-dev/transactions#id_24388值得一讀。它解釋了爲什麼你需要兩個evals。您總是希望在該部分的「調用語句」表的第一行中運行更新。也就是說,當涉及多個更新時,它們應該總是由只讀查詢控制。從更新中調用更新至多是不可能的,而且最危險。 – mblakele