Re: [MarkLogic Dev General] XDMP-CONFLICTINGUPDATES: while using xdmp.nodeReplace

2016-09-28 Thread Justin Makeig
The general pattern for doing updates on persisted JSON documents in JavaScript 
is to 
  1) get the document 
  2) turn it into an object 
  3) update the object
  4) replace the document node with the updated object

Here's an example that updates the `balance` property of every document in the 
`accounts` collection: 

declareUpdate();
for(var doc of fn.collection('accounts')) {
  var account = doc.toObject();
  account.balance = account.balance * 1.05;
  xdmp.nodeReplace(doc, account);
} 

Note that you also need a declareUpdate(). The transaction is committed (or 
rolledback) automatically, so you don't need the xdmp.commit().

Justin

--
Justin Makeig
Director, Product Management
MarkLogic
jmak...@marklogic.com

> On Sep 28, 2016, at 1:46 PM, Shiv Shankar  wrote:
> 
> Hi Rob,
> Thanks for quick reply,
> 
> Here is the sample scenario.
> 
> I would be building random data and put in to newObjData in a for loop.
> 
> 01.json = {"firstName": "abc", "lastName": "xyz"}
> 
> newObjectData.firstName= "Donald";
> 
>  for Loop
> {
> xdmp.nodeReplace(cts.doc("/test/01.json"),newObjectData);
> xdmp.commit();
> }
> 
> 
> 
> 
> 
> On Wed, Sep 28, 2016 at 4:37 PM, Rob Szkutak  
> wrote:
> Hi,
> 
> Do you have a reproducible case of this I could look at?
> 
> Best,
> Rob
> 
> Rob Szkutak
> Senior Consultant
> MarkLogic Corporation
> rob.szku...@marklogic.com
> www.marklogic.com
> 
> From: Shiv Shankar [shiv.shivshan...@gmail.com]
> Sent: Wednesday, September 28, 2016 3:35 PM
> To: general@developer.marklogic.com; Rob Szkutak
> Subject: XDMP-CONFLICTINGUPDATES: while using xdmp.nodeReplace
> 
> Hi Rob,
> 
> I am getting XDMP-CONFLICTINGUPDATES: while using xdmp.nodeReplace to update 
> JSON attributes  in FOR loop, instead of over-writing entire document. Any 
> advice.
> 
> BTW, I used xdmp.eval, but it is not identifying the java script variables.
> 
> Thanks
> ShivShankar.
> 
> ___
> General mailing list
> General@developer.marklogic.com
> Manage your subscription at: 
> http://developer.marklogic.com/mailman/listinfo/general


___
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] XDMP-CONFLICTINGUPDATES: while using xdmp.nodeReplace

2016-09-28 Thread Shiv Shankar
Hi Rob,
Thanks for quick reply,

Here is the sample scenario.

I would be building random data and put in to newObjData in a for loop.

01.json = {"firstName": "abc", "lastName": "xyz"}

newObjectData.firstName= "Donald";

 for Loop
{
xdmp.nodeReplace(cts.doc("/test/01.json"),newObjectData);
xdmp.commit();
}





On Wed, Sep 28, 2016 at 4:37 PM, Rob Szkutak 
wrote:

> Hi,
>
> Do you have a reproducible case of this I could look at?
>
> Best,
> Rob
>
> Rob Szkutak
> Senior Consultant
> MarkLogic Corporation
> rob.szku...@marklogic.com
> www.marklogic.com
>
> --
> *From:* Shiv Shankar [shiv.shivshan...@gmail.com]
> *Sent:* Wednesday, September 28, 2016 3:35 PM
> *To:* general@developer.marklogic.com; Rob Szkutak
> *Subject:* XDMP-CONFLICTINGUPDATES: while using xdmp.nodeReplace
>
> Hi Rob,
>
> I am getting XDMP-CONFLICTINGUPDATES: while using xdmp.nodeReplace to
> update JSON attributes  in FOR loop, instead of over-writing entire
> document. Any advice.
>
> BTW, I used xdmp.eval, but it is not identifying the java script variables.
>
> Thanks
> ShivShankar.
>
___
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] XDMP-CONFLICTINGUPDATES: while using xdmp.nodeReplace

2016-09-28 Thread Rob Szkutak
Hi,

Do you have a reproducible case of this I could look at?

Best,
Rob

Rob Szkutak
Senior Consultant
MarkLogic Corporation
rob.szku...@marklogic.com
www.marklogic.com


From: Shiv Shankar [shiv.shivshan...@gmail.com]
Sent: Wednesday, September 28, 2016 3:35 PM
To: general@developer.marklogic.com; Rob Szkutak
Subject: XDMP-CONFLICTINGUPDATES: while using xdmp.nodeReplace

Hi Rob,

I am getting XDMP-CONFLICTINGUPDATES: while using xdmp.nodeReplace to update 
JSON attributes  in FOR loop, instead of over-writing entire document. Any 
advice.

BTW, I used xdmp.eval, but it is not identifying the java script variables.

Thanks
ShivShankar.
___
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


[MarkLogic Dev General] XDMP-CONFLICTINGUPDATES: while using xdmp.nodeReplace

2016-09-28 Thread Shiv Shankar
Hi,
I am getting XDMP-CONFLICTINGUPDATES: while using xdmp.nodeReplace to
update JSON attributes, instead of over-writing entire document. Any advice.

BTW, I used xdmp.eval, but it is not identifying the java script variables.

Thanks
ShivShankar.
___
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general