Re: [MarkLogic Dev General] General Digest, Vol 147, Issue 53
Hi Justin I'm simply copying some of the values from first-collection into second colleciton on finding the values in 2nd collection based on search criteria. Here is my entire code for one record. If there are multiple records in first-collection, then this conflict is occuring. Code declareUpdate(); var json = "/MarkLogic/json/json.xqy"; var cpf = require("/MarkLogic/cpf/cpf.xqy"); var dls = require("/MarkLogic/dls.xqy"); var jsearch = require("/MarkLogic/jsearch.sjs"); var transition; //var doc = cts.doc(uri).toObject(); //var id = doc.personId; var id = "1234"; var rawColls = require("/MarkLogic/jsearch.sjs").collections(["first-collection"]); var matColl = require("/MarkLogic/jsearch.sjs").collections(['second-collection']); var rawJson; var count=0; var matViewUri =null; var rawUri = null; // Reading from RAW Sources. var tempObj = rawColls.documents() .where(rawColls.byExample({personId: id})) .result(); var length = 0; var rawResponse = rawColls.documents() .where(rawColls.byExample({personId: id})) .result('iterator'); if ( tempObj.estimate != 0 ) { rawUri = tempObj.results.uri; var materialView = matColl.documents() .where(matColl.byExample({personId: id})).result(); if (materialView.results!=null) { // If records found in the second collection View. matViewUri = materialView.results[0].uri; for (var result of rawResponse.results) { var newObj = {}; var matOriginalDoc = cts.doc(matViewUri); var dateNow =new Date().toUTCString(); // if (doc.firstname !=null) newObj.firstName = result.document.firstname; // if (doc.lastName !=null) newObj.lastName = result.document.lastname; // if (doc.dateOfBirth !=null) newObj.dateOfBirth = result.document.dob; // if (doc.city !=null) newObj.city = result.document.city; newObj.modifiedDate = new Date().toUTCString(); count++; xdmp:eval('xdmp.nodeReplace(matOriginalDoc,newObj)',newObj,{ "isolation" : "different-transaction", "preventDeadlocks" : true }); } } else { // create new document in 2nd collection for that PersonId; xdmp.log(" Create a new document"); } } else { xdmp.log(" ERROR: NO RECORDS FOUND IN first collection"); } On Mon, Oct 3, 2016 at 3:28 PM, Justin Makeig wrote: > I still don't understand what your code is trying to do. Can you please > describe in words what you're trying to accomplish? Where does `matViewUri` > come from? How does it relate to `{personId: id}`? > > Justin > > > > On Oct 3, 2016, at 7:08 AM, Shiv Shankar > wrote: > > > > Hi Justin, > > Here is the actual code that returns XDMP-CONFLICTINGUPDATES Error:. > > > > --- > > declareUpdate(); > > var mainDataResponse = > > rawColls.documents() > > .where(rawColls.byExample({personId: id})) > > .result('iterator'); > > > > for (var result of mainDataResponse.results) { > > > > var normalizedViewObj = cts.doc(matViewUri).toObject(); > > > > var matOriginalDoc = cts.doc(matViewUri); > > > > var dateNow =new Date().toUTCString(); > > > > // if (doc.firstname !=null) > > normalizedViewObj.firstName = result.document.firstname; > > > > // if (doc.lastName !=null) > > normalizedViewObj.lastName = result.document.lastname; > > // if (doc.dateOfBirth !=null) > > normalizedViewObj.dateOfBirth = result.document.dob; > > > > xdmp.nodeReplace(cts.doc(matViewUri),normalizedViewObj), > > normalizedViewObj = null; > > > > } > > > > --- > > > > On Thu, Sep 29, 2016 at 3:00 PM, marklogic.com> wrote: > > Send General mailing list submissions to > > general@developer.marklogic.com > > > > To subscribe or unsubscribe via the World Wide Web, visit > > http://developer.marklogic.com/mailman/listinfo/general > > or, via email, send a message with subject or body 'help' to > > general-requ...@developer.marklogic.com > > > > You can reach the person managing the list at > > general-ow...@developer.marklogic.com > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of General digest..." > > > > > > Today's Topics: > > > >1. Re: General Digest, Vol 147, Issue 51 (Justin Makeig) > > > > > > -- > > > > Message: 1 > > Date: Thu, 29 Sep 2016 16:32:44 + > > From: Justin Makeig > > Subject: Re: [MarkLogic Dev General] General Digest, Vol 147, Issue 51 > > To: Shiv Shankar > > Cc: "general@developer.marklogic.com" > > > > Message-ID: <22fded82-fc67-4aad-b1f9-2eecb5b6a...@marklogic.com> > > Content-Type: text/plain; charset="us-ascii" > > > > Can you show your actual code? > > > > Justin > > > > > > -- > > Justin Makeig > > Director, Product Management > > MarkLogic > > jmak...@marklogic.com > > > > > > > On Sep 29, 2016, at 7:09 AM, Shiv Shankar > wrote: > > > > > > HI Justin, > > > Thanks for your quick reply. However, I used both > declareUpdate({explicitCommit: true}); and
Re: [MarkLogic Dev General] General Digest, Vol 147, Issue 53
I still don't understand what your code is trying to do. Can you please describe in words what you're trying to accomplish? Where does `matViewUri` come from? How does it relate to `{personId: id}`? Justin > On Oct 3, 2016, at 7:08 AM, Shiv Shankar wrote: > > Hi Justin, > Here is the actual code that returns XDMP-CONFLICTINGUPDATES Error:. > > --- > declareUpdate(); > var mainDataResponse = > rawColls.documents() > .where(rawColls.byExample({personId: id})) > .result('iterator'); > > for (var result of mainDataResponse.results) { > > var normalizedViewObj = cts.doc(matViewUri).toObject(); > > var matOriginalDoc = cts.doc(matViewUri); > > var dateNow =new Date().toUTCString(); > > // if (doc.firstname !=null) > normalizedViewObj.firstName = result.document.firstname; > > // if (doc.lastName !=null) > normalizedViewObj.lastName = result.document.lastname; > // if (doc.dateOfBirth !=null) > normalizedViewObj.dateOfBirth = result.document.dob; > > xdmp.nodeReplace(cts.doc(matViewUri),normalizedViewObj), > normalizedViewObj = null; > > } > > --- > > On Thu, Sep 29, 2016 at 3:00 PM, > wrote: > Send General mailing list submissions to > general@developer.marklogic.com > > To subscribe or unsubscribe via the World Wide Web, visit > http://developer.marklogic.com/mailman/listinfo/general > or, via email, send a message with subject or body 'help' to > general-requ...@developer.marklogic.com > > You can reach the person managing the list at > general-ow...@developer.marklogic.com > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of General digest..." > > > Today's Topics: > >1. Re: General Digest, Vol 147, Issue 51 (Justin Makeig) > > > -- > > Message: 1 > Date: Thu, 29 Sep 2016 16:32:44 + > From: Justin Makeig > Subject: Re: [MarkLogic Dev General] General Digest, Vol 147, Issue 51 > To: Shiv Shankar > Cc: "general@developer.marklogic.com" > > Message-ID: <22fded82-fc67-4aad-b1f9-2eecb5b6a...@marklogic.com> > Content-Type: text/plain; charset="us-ascii" > > Can you show your actual code? > > Justin > > > -- > Justin Makeig > Director, Product Management > MarkLogic > jmak...@marklogic.com > > > > On Sep 29, 2016, at 7:09 AM, Shiv Shankar > > wrote: > > > > HI Justin, > > Thanks for your quick reply. However, I used both > > declareUpdate({explicitCommit: true}); and declareUpdate(); Still same > > issue. > > > > I am just reading from one collection and updating into another document in > > a different collection. I managed with insertDocument, but this over writes > > the docs which I don't want. I just want to update the attributes ( it is > > like UPDATE SET field1:=value, field2=value in loop in oracle world) > > > > Note: I used lock/unlock options, but getting no lock on that target > > record. I used isolation level as part of eval. Couldn't get through it. > > XDMP-CONFLICTINGUPDATES: xdmp.eval("//{explicitCommit: > > true}\ndeclareUpdate(); \nvar json = \"/Mark...", {}, > xmlns="xdmp:eval">67298589469423423423/) > > --Conflicting updates xdmp.nodeReplace(cts.doc(" > > > > > > Any thoughts? > > > > On Thu, Sep 29, 2016 at 7:55 AM, > > wrote: > > Send General mailing list submissions to > > general@developer.marklogic.com > > > > To subscribe or unsubscribe via the World Wide Web, visit > > http://developer.marklogic.com/mailman/listinfo/general > > or, via email, send a message with subject or body 'help' to > > general-requ...@developer.marklogic.com > > > > You can reach the person managing the list at > > general-ow...@developer.marklogic.com > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of General digest..." > > > > > > Today's Topics: > > > >1. Re: XDMP-CONFLICTINGUPDATES: whileusing xdmp.nodeReplace > > (Justin Makeig) > >2. Re: mlcp Transaction Errors - SVC-EXTIME and XDMP-NOTXN #CGO# > > (Jain, Abhishek) > > > > > > -- > > > > Message: 1 > > Date: Wed, 28 Sep 2016 21:02:26 + > > From: Justin Makeig > > Subject: Re: [MarkLogic Dev General] XDMP-CONFLICTINGUPDATES: while > > using xdmp.nodeReplace > > To: MarkLogic Developer Discussion > > Message-ID: <4136b8ca-113a-4373-b6d3-e54d34f15...@marklogic.com> > > Content-Type: text/plain; charset="us-ascii" > > > > 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.
Re: [MarkLogic Dev General] General Digest, Vol 147, Issue 53
Hi Justin, Here is the actual code that returns XDMP-CONFLICTINGUPDATES Error:. --- declareUpdate(); var mainDataResponse = rawColls.documents() .where(rawColls.byExample({personId: id})) .result('iterator'); for (var result of mainDataResponse.results) { var normalizedViewObj = cts.doc(matViewUri).toObject(); var matOriginalDoc = cts.doc(matViewUri); var dateNow =new Date().toUTCString(); // if (doc.firstname !=null) normalizedViewObj.firstName = result.document.firstname; // if (doc.lastName !=null) normalizedViewObj.lastName = result.document.lastname; // if (doc.dateOfBirth !=null) normalizedViewObj.dateOfBirth = result.document.dob; xdmp.nodeReplace(cts.doc(matViewUri),normalizedViewObj), normalizedViewObj = null; } --- On Thu, Sep 29, 2016 at 3:00 PM, wrote: > Send General mailing list submissions to > general@developer.marklogic.com > > To subscribe or unsubscribe via the World Wide Web, visit > http://developer.marklogic.com/mailman/listinfo/general > or, via email, send a message with subject or body 'help' to > general-requ...@developer.marklogic.com > > You can reach the person managing the list at > general-ow...@developer.marklogic.com > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of General digest..." > > > Today's Topics: > >1. Re: General Digest, Vol 147, Issue 51 (Justin Makeig) > > > -- > > Message: 1 > Date: Thu, 29 Sep 2016 16:32:44 + > From: Justin Makeig > Subject: Re: [MarkLogic Dev General] General Digest, Vol 147, Issue 51 > To: Shiv Shankar > Cc: "general@developer.marklogic.com" > > Message-ID: <22fded82-fc67-4aad-b1f9-2eecb5b6a...@marklogic.com> > Content-Type: text/plain; charset="us-ascii" > > Can you show your actual code? > > Justin > > > -- > Justin Makeig > Director, Product Management > MarkLogic > jmak...@marklogic.com > > > > On Sep 29, 2016, at 7:09 AM, Shiv Shankar > wrote: > > > > HI Justin, > > Thanks for your quick reply. However, I used both > declareUpdate({explicitCommit: true}); and declareUpdate(); Still same > issue. > > > > I am just reading from one collection and updating into another document > in a different collection. I managed with insertDocument, but this over > writes the docs which I don't want. I just want to update the attributes ( > it is like UPDATE SET field1:=value, field2=value in loop in oracle world) > > > > Note: I used lock/unlock options, but getting no lock on that target > record. I used isolation level as part of eval. Couldn't get through it. > > XDMP-CONFLICTINGUPDATES: xdmp.eval("//{explicitCommit: > true}\ndeclareUpdate(); \nvar json = \"/Mark...", {}, xmlns="xdmp:eval">67298589469423423423/) > --Conflicting updates xdmp.nodeReplace(cts.doc(" > > > > > > Any thoughts? > > > > On Thu, Sep 29, 2016 at 7:55 AM, marklogic.com> wrote: > > Send General mailing list submissions to > > general@developer.marklogic.com > > > > To subscribe or unsubscribe via the World Wide Web, visit > > http://developer.marklogic.com/mailman/listinfo/general > > or, via email, send a message with subject or body 'help' to > > general-requ...@developer.marklogic.com > > > > You can reach the person managing the list at > > general-ow...@developer.marklogic.com > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of General digest..." > > > > > > Today's Topics: > > > >1. Re: XDMP-CONFLICTINGUPDATES: whileusing xdmp.nodeReplace > > (Justin Makeig) > >2. Re: mlcp Transaction Errors - SVC-EXTIME and XDMP-NOTXN #CGO# > > (Jain, Abhishek) > > > > > > -- > > > > Message: 1 > > Date: Wed, 28 Sep 2016 21:02:26 + > > From: Justin Makeig > > Subject: Re: [MarkLogic Dev General] XDMP-CONFLICTINGUPDATES: while > > using xdmp.nodeReplace > > To: MarkLogic Developer Discussion > > Message-ID: <4136b8ca-113a-4373-b6d3-e54d34f15...@marklogic.com> > > Content-Type: text/plain; charset="us-ascii" > > > > 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 > > MarkLo