[MarkLogic Dev General] Query on commit in MarkLogic 5.0
Vedavalli Radhika
radhika.kv at gmail.com
Wed Jun 13 15:11:51 PDT 2012
Thanks Damon and John. Guess my understanding on commit was wrong.
Transactions are achieveable only using semi-colon.
Talking on in-memory update, this is what I want to achieve. But your
query works fine if we want to insert a node at the end of a document.
But I want to update a text node at the middle of the document. I have
to painfully create three transactions, declaring all the required
namespaces and functions to insert, update and delete this temporary
document.
From: Damon Feldman <Damon.Feldman at marklogic.com>
Subject: Re: [MarkLogic Dev General] Query on commit in MarkLogic 5.0
To: MarkLogic Developer Discussion <general at developer.marklogic.com>
Message-ID:
<D20C296D14127D4EBD176AD949D8A75A205703FA38 at EXCHG-BE.marklogic.com>
Content-Type: text/plain; charset="utf-8"
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 6/13/12, Vedavalli Radhika <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.
>
More information about the General
mailing list