Reputation: 348
This Question is in reference with Data Hub Framework-
I am having 3-4 conditions in which i am doing operations like xdmp:node-replace
and xdmp:document-delete
and after all the conditions i am trying to insert the document using xdmp:document-insert
.
When i am running the conditions independently by commenting the other conditions then it is working fine but if i am trying to run 2 or more conditions together- i am getting XDMP-CONFLICTINGUPDATES
$envelope is coming from STAGING Database which i am using in writer.xqy
The code sample is as below-
let $con1 := if($envelope/*:test/text() eq "abc")
then xdmp:node-replace(....) else ()
let $con2 := if($envelope/*:test/text() eq "123")
then xdmp:node-replace(....) else ()
let $con1 := if($envelope/*:test/text() eq "cde")
then xdmp:document-delete(....) else ()
return if($envelope//*FLAG/text() eq "1")
then
xdmp:document-insert($id, $envelope, xdmp:default-permissions(), map:get($options, "entity"))
Any Suggestions ?
Upvotes: 1
Views: 1166
Reputation: 3138
This is multi transaction statement. There are multiple ways to handle it in your scenario:
Upvotes: 0
Reputation: 515
Likely the XQuery statement above is attempting multiple updates to the same node in the same single-statement transaction. The xdmp:node-replace
calls are performing updates at each operation to the same node. See the documentation for more details.
Here are two solutions that may work for you
Upvotes: 4
Reputation: 3609
XDMP-ConflictingUpdates
means you are trying to update the same node more than once within a single transaction. Solving these types of errors can be infamously tricky and are a rite of passage for every MarkLogician.
In your case, this is caused by updating a node with xdmp:node-replace
and then updating the document node which is the parent of that node with xdmp:document-insert
. Thus, because you are updating both the node and its parent, you are in effect updating that node twice causing the error. Or, this may also occur from trying to both delete and insert a document at the same URI within the same transaction.
Here is a simple query you can run in QConsole to reproduce this behavior:
xquery version "1.0-ml";
xdmp:document-insert("/test.xml", <test><value></value></test>);
xquery version "1.0-ml";
let $d := fn:doc("/test.xml")
let $_ := xdmp:node-replace($d//value, <value>test</value>)
return
xdmp:document-insert("/test.xml", $d)
In the case of this demonstration, as well as your code, the xdmp:document-insert
is redundant and can simply be removed.
Upvotes: 4