Last active
December 11, 2020 14:37
-
-
Save ableasdale/7df47292f21defa2bb0f15b284d0213d to your computer and use it in GitHub Desktop.
MarkLogic: In Forest Eval example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "1.0-ml"; | |
(: | |
The following XQuery code demonstrates a technique to force an "in forest eval" of a call to xdmp:document-insert(). | |
This code will force a document insert to get evaluated within the context of a specific forest (Documents2) | |
Note that the practice outlined in this code (or similar) can have the potential to lead to an increased chance of | |
XDMP-DBDUPURI URIs as the code effectively bypasses the normal xdmp:document-assign() process that assigns a URI to | |
a given forest based on the hash of it's URI key. | |
This code is for demonstration purposes only. | |
:) | |
declare function local:in-forest-eval($xquery as xs:string, $vars as item()*, $forest-id as xs:unsignedLong) { | |
xdmp:eval( | |
$xquery, | |
$vars, | |
<options xmlns="xdmp:eval"> | |
<isolation>different-transaction</isolation> | |
<database>{$forest-id}</database> | |
</options>) | |
}; | |
local:in-forest-eval("xdmp:document-insert('/foo1.xml', <foo>1</foo>)", (), xdmp:forest("Documents2")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment