javascriptmarklogicsjs

Marklogic Server Side Javascript: XDMP-CONFLICTINGUPDATES while using explicit commit


I've been having problems with conflicting updates in Marklogic. I'm aware of the cause, but I don't know how to fix it. I have 1 main (.sjs) file which calls two different (.sjs) files which both update a set of documents. In the main file I use: declareUpdate({explicitCommit: true}); and then in the separate files I use the command xdmp.commit(); after updating the documents. However, I'm still getting: XDMP-CONFLICTINGUPDATES.

Part of the code: Main.sjs:

function main(){
  declareUpdate({explicitCommit: true});
  function.to.file.1();
  function.to.file.2();
}

file1.sjs:

//make some docs and insert them into ML
function file1Function(){
    for (let d of someCollectionOfData) {
      xdmp.documentInsert('/a/uri/filexx.json', d, {collections: aCollectionName1});
    };
    xdmp.commit();
}

file2.sjs:

//adjust docs made in file1 and put them back into ML
funtion file2Function(){
  for (let d of xdmp.directory('/location/of/aCollectionName1/','infinity')) {
    let dObj = d.toObject();
    dObj.addSomething = 'something';
    xdmp.documentInsert(fn.documentUri(d), dObj, {collections: aCollectionName1});
  }
  xdmp.commit();
}

Solution

  • It must mean your file1 is located inside '/location/of/aCollectionName1/'. Keep in mind that MarkLogic doesn't commit immediately when you invoke xdmp.commit(). Actual persisting is always postponed until after all code has executed. It therefor doesn't make much sense to invoke xdmp.commit() more than once in one request. You won't be able to read your updates after xdmp.commit().

    HTH!