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 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] How XSL will work insted of xquery If we have more then one same record in XML, ignore them and extract only rest data

2016-09-28 Thread Nalini Shrma
thanks, thats is working

On Thu, Sep 29, 2016 at 12:25 AM, Evan Lenz  wrote:

> You could output it only if the current group has one item. Inside
> :
>
>   
> 
>   
>
> Evan
>
> Evan Lenz
> President, Lenz Consulting Group, Inc.
> http://lenzconsulting.com
>
> On Wed, Sep 28, 2016 at 11:42 AM, Nalini Shrma 
> wrote:
>
>> Hi,
>>
>> I have one problem where i am writing XSL insted of XQUERY to How XSL
>> will work If we have more then one same record in XML, ignore them and
>> extract only rest data. my xsl code handling only duplicate value, i need
>> only that record which is not duplicate or more then one. Below is my XSL:
>>
>> > group-by="id">
>>
>> Input:
>>
>> > encoding="UTF-8"?>074074001074
>>
>> Expected output:
>>
>>   
>>   001
>>   
>>
>>
>> ___
>> 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
>
>
___
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] How XSL will work insted of xquery If we have more then one same record in XML, ignore them and extract only rest data

2016-09-28 Thread Evan Lenz
You could output it only if the current group has one item. Inside
:

  

  

Evan

Evan Lenz
President, Lenz Consulting Group, Inc.
http://lenzconsulting.com

On Wed, Sep 28, 2016 at 11:42 AM, Nalini Shrma 
wrote:

> Hi,
>
> I have one problem where i am writing XSL insted of XQUERY to How XSL will
> work If we have more then one same record in XML, ignore them and extract
> only rest data. my xsl code handling only duplicate value, i need only that
> record which is not duplicate or more then one. Below is my XSL:
>
>  group-by="id">
>
> Input:
>
>  encoding="UTF-8"?>074074001074
>
> Expected output:
>
>   
>   001
>   
>
>
> ___
> 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


[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


Re: [MarkLogic Dev General] How XSL will work insted of xquery If we have more then one same record in XML, ignore them and extract only rest data

2016-09-28 Thread Nalini Shrma
sorry, that is working,

On Thu, Sep 29, 2016 at 12:12 AM, Nalini Shrma 
wrote:

> Hi,
>
> I have one problem where i am writing XSL insted of XQUERY to How XSL will
> work If we have more then one same record in XML, ignore them and extract
> only rest data. my xsl code handling only duplicate value, i need only that
> record which is not duplicate or more then one. Below is my XSL:
>
>  group-by="id">
>
> Input:
>
>  encoding="UTF-8"?>074074001074
>
> Expected output:
>
>   
>   001
>   
>
>
___
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general


[MarkLogic Dev General] How XSL will work insted of xquery If we have more then one same record in XML, ignore them and extract only rest data

2016-09-28 Thread Nalini Shrma
Hi,

I have one problem where i am writing XSL insted of XQUERY to How XSL will
work If we have more then one same record in XML, ignore them and extract
only rest data. my xsl code handling only duplicate value, i need only that
record which is not duplicate or more then one. Below is my XSL:



Input:

074074001074

Expected output:

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


Re: [MarkLogic Dev General] Validate XML documents while ingesting and maintain logs of failed documents #CGO#

2016-09-28 Thread Mary Holstege
You need to throw an error to abort the whole transaction. Call fn:error from 
the catch block.

//Mary

On Sep 27, 2016 10:57 PM, "Jain, Abhishek"  
wrote:

Hi Greet,



I tried to implement pre-commit solution. In my action module I am trying check 
if input xml adheres to xml my predefined xml schema

Then only it should commit the file if not it should fail.

In order to do so, I am written pre-trigger  action module as follows –



xquery version '1.0-ml';

(: evaluate this against the database specified

   in the trigger definition (test in this example)

:)

xdmp:document-insert("/modules/log.xqy",

  text{ "

xquery version '1.0-ml';

import module namespace trgr='http://marklogic.com/xdmp/triggers'

   at '/MarkLogic/triggers.xqy';

declare variable $trgr:uri as xs:string external;

try {  (xdmp:log(fn:concat('*Document ', $trgr:uri, ' was created.*')),

   let $root := fn:doc($trgr:uri)/*

   return $root)

}

catch ($e) { 'Validation failed: ', $e/error:format-string/text() }

"}, xdmp:permission('app-user', 'execute'))



My question is how do I force commit to fail. I tried returning fn:false() in 
above try block but it doesn’t work.

What should I return in try block to prevent ingestion. May be a silly one but 
I am not getting around it.



Thanks,

Abhishek Jain



From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Jain, Abhishek
Sent: Wednesday, September 21, 2016 8:26 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Validate XML documents while ingesting and 
maintain logs of failed documents #CGO#



WARNING: Kindly be aware the Sender Address on this mail may be forged. It 
appears to be from capgemini.com but the message has been received from a 
server outside Capgemini Group perimeter. User discretion is necessary before 
performing actions mentioned in this mail.

Thanks for  the quick input, just had a look at pre-commit trigger, looks like 
a solution, will give it a try.

MLCP/pre-commit will do, Writing off CPF solution for post-commit over-head 
reason, As I need to upload 1 TB Data.



Thank a lot.

[Email_CBE.gif]Abhishek Jain

Associate Consultant

Capgemini India | Hyderabad



From: 
general-boun...@developer.marklogic.com
 [mailto:general-boun...@developer.marklogic.com] On Behalf Of Geert Josten
Sent: Wednesday, September 21, 2016 6:53 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Validate XML documents while ingesting and 
maintain logs of failed documents #CGO#



Hi Abhishek,



Sounds right overall. An MLCP transform gives some flexibility when you want to 
validate or not. If you want to enforce it more strictly, you can use a 
pre-commit trigger, and deny commit if it doesn’t validate by (re)throwing an 
error (or not catching the validate error).



I would recommend using a pre-commit trigger over CPF if it is only for 
validation. CPF comes with extra overhead, and actions run in post-commit too. 
You would not be able to prevent inserts, but only able to flag docs as being 
invalid..



Cheers,

Geert



From: 
mailto:general-boun...@developer.marklogic.com>>
 on behalf of "Jain, Abhishek" 
mailto:abhishek.b.j...@capgemini.com>>
Reply-To: MarkLogic Developer Discussion 
mailto:general@developer.marklogic.com>>
Date: Wednesday, September 21, 2016 at 3:03 PM
To: "general@developer.marklogic.com" 
mailto:general@developer.marklogic.com>>
Subject: [MarkLogic Dev General] Validate XML documents while ingesting and 
maintain logs of failed documents #CGO#



Hi Folks,



I’m working on a use-case where I need to ingest bulk documents into Marklogic, 
only those documents which adhere to predefined ( have written my own)

XML schema should be loaded into DB. If fails then details should be written in 
a log file. My approach to achieve this so far is :



1.   Create an XSD.

2.   Write a MLCP transformation module or content processing framework 
module

3.   Validate content of each document inside the module and using try … 
catch block

4.   If content is valid - insert , if not write to failed list (logs)



Am I going right ?

Can anyone share with me the best approach ?

Is there any other way of doing this than mlcp and CPF ?



Thanks and Regards,

[Email_CBE.gif]Abhishek Jain

Associate Consultant

People matter, results count.





This message contains information that may be privileged or confidential and is 
the property of the Capgemini Group. It is intended only for the person to whom 
it is addressed. If you are not the intended recipient, you are not authorized 
to read, print, retain, copy, disseminate, distribute, or use this message or 
any part thereof. If you receive this message in error, please notify the 
sender immediately and delete all copies of this message.