[MarkLogic Dev General] Query on commit in MarkLogic 5.0

Damon Feldman Damon.Feldman at marklogic.com
Wed Jun 13 12:24:49 PDT 2012


Radhika,

As John says, outside the header (where the declarations and functions are) a semicolon is a transaction separator, so you can make multiple changes without having to use commit() or the non-default transaction modes:

xdmp:document-insert("/test.xml", <test/>)

; (: transaction! :)

xdmp:node-insert-child(doc("/test.xml")/test, <child/>)

; (: tx :)

doc("/test.xml")


But you can usually update the document in memory and then store what you want:

let $doc := <article><abstract>short</abstract><content>longer version</content></article>
let $new-doc := element article {
  $doc/@*,  (: all attributes :)
  $doc/node(),  (: all elements :)
  <footnote>see also www.foo.com/bar</footnote> (:added element :)
}

return xdmp:document-insert("/test.xml", $new-doc)

; (: transaction separator so we can see the inserted doc after the transaction commits :)
doc("/test.xml")

Yours,
Damon

From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of John Zhong
Sent: Wednesday, June 13, 2012 8:43 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Query on commit in MarkLogic 5.0

Hi,

I think you must use the semicolon (;) to commit the transactions, check here:

http://docs.marklogic.com/5.0doc/docapp.xqy#display.xqy?fname=http://pubs/5.0doc/xml/dev_guide/transactions.xml%2355092

John
On Wed, Jun 13, 2012 at 8:01 PM, Vedavalli Radhika <radhika.kv at gmail.com<mailto:radhika.kv at gmail.com>> wrote:
Hi,
Query on commit in ML 5.0.
I wanted to achieve updating an xml within a same transaction. I came
across xdmp:commit in ML5.0 and thought that this will solve our
issue.
But I was getting the below error when I executed this script.
Am I missing anything here?

let $transaction1 := (xdmp:set-transaction-mode("update"),
                   xdmp:document-insert("/example.xml",  <a><b>bbb</b></a>),
                   xdmp:commit())

let $transaction2 := (xdmp:set-transaction-mode("update"),
                   xdmp:node-replace(doc("/example.xml")/a/b, <c>ccc</c>),
                   xdmp:commit())
                   return "document updated"

Message thrown: [1.0-ml] XDMP-CONFLICTINGUPDATES:
xdmp:node-replace(fn:doc("/example.xml")/a/b, <c>ccc</c>) --
Conflicting updates xdmp:node-replace(fn:doc("/example.xml")/a/b,
<c>ccc</c>) and xdmp:document-insert("/example.xml",
<a><b>bbb</b></a>, (), (), 0)

Thanks,
Radhika.
_______________________________________________
General mailing list
General at developer.marklogic.com<mailto:General at developer.marklogic.com>
http://community.marklogic.com/mailman/listinfo/general

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://community.marklogic.com/pipermail/general/attachments/20120613/60194536/attachment.html 


More information about the General mailing list