Reputation: 93
Well, we have what should be a pretty simple scenario.
We utilize Marklogic dls library to manage documents, so below is the code
The variable passed in looks like one below:
$doc: =<root>
<node1>
<subnode/></node1>
<node2>
<status/>
</node2>
<root>
The function replaces/updates couple of different nodes in the doc. Checks in and then returns a map of id-version pairs.
declare function process-and-version($doc) {
for $sb in $doc/node1/subnode
return if ($sb/node3) then
xdmp:node-replace($sb/node3, <node3>foo</node>)
else
xdmp:node-insert-after($sb, <node3>foo</node>),
xdmp:node-replace($doc/status, <status>{$status}</status>),
dls:document-checkout-update-checkin("fn:base-uri($doc), $doc, "", fn:true()),
let $updated-version:=
<entry>{
let $version := c:get-latest-version($uri)
(:another function in our lib that uses cts:search:)
return ($doc/node1, <version>{$version}</version>)
}
</entry>
return $updated-version
};
We are using XRAY to test drive this and getting the following error:
<error:error xsi:schemaLocation="http://marklogic.com/xdmp/error error.xsd" xmlns:error="http://marklogic.com/xdmp/error" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<error:code>XDMP-CONFLICTINGUPDATES</error:code>
<error:name></error:name>
<error:xquery-version>1.0-ml</error:xquery-version>
<error:message>Conflicting updates</error:message>
Many thanks in advance for help,
im
Upvotes: 0
Views: 316
Reputation: 20414
The problem lies in the fact that the xdmp:node-* functions operate on the document stored in the database. You wouldn't need to call an update to save those changes. Most likely the dls update function replaces the entire document, causing a conflict with those node updates.
You are looking for in-memory updates. The dls library itself contains some functions that do just that, but those are private. I suggest looking into the helper library mentioned below for that, or if the changes are relatively simple you can just reconstruct the document. That is done very often, and is no performance hit.
mem-update: https://github.com/marklogic/commons/tree/master/memupdate
HTH!
Upvotes: 3