Understanding Transaction Boundaries in server side JavaScript- Marklogic









up vote
0
down vote

favorite












I wanted to check the transactional boundaries in Server-Side JavaScript in MarkLogic.



So I wrote the below code. I wanted to see the document "/docs/first.json" only within this transaction. Basically, I wanted each statements within a server side JavasSript to see the updates of each other statements within the transaction and it shouldn't be visible outside the transaction. But when I ran the below code I got the document "/docs/first.json" which is the result of fn.doc("/docs/first.json"), which runs in the same transaction. But when I opened a new session and tried to fetch the document "/docs/first.json", I understood that the document had actually got ingested into the database and hence its visible outside the transaction as well.



Can someone please correct where I am going wrong in this code so that I will be able to view the doc only within the transaction and not outside the transaction. I was able to achieve this using Xquery using ";" as statement separators.



declareUpdate(explicitCommit: true);
xdmp.eval('declareUpdate(); xdmp.documentInsert("/docs/first.json","first": 1);',commit:'explicit',transactionMode:'update')
xdmp.eval('fn.doc("/docs/first.json")',transactionMode:"query")









share|improve this question



























    up vote
    0
    down vote

    favorite












    I wanted to check the transactional boundaries in Server-Side JavaScript in MarkLogic.



    So I wrote the below code. I wanted to see the document "/docs/first.json" only within this transaction. Basically, I wanted each statements within a server side JavasSript to see the updates of each other statements within the transaction and it shouldn't be visible outside the transaction. But when I ran the below code I got the document "/docs/first.json" which is the result of fn.doc("/docs/first.json"), which runs in the same transaction. But when I opened a new session and tried to fetch the document "/docs/first.json", I understood that the document had actually got ingested into the database and hence its visible outside the transaction as well.



    Can someone please correct where I am going wrong in this code so that I will be able to view the doc only within the transaction and not outside the transaction. I was able to achieve this using Xquery using ";" as statement separators.



    declareUpdate(explicitCommit: true);
    xdmp.eval('declareUpdate(); xdmp.documentInsert("/docs/first.json","first": 1);',commit:'explicit',transactionMode:'update')
    xdmp.eval('fn.doc("/docs/first.json")',transactionMode:"query")









    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I wanted to check the transactional boundaries in Server-Side JavaScript in MarkLogic.



      So I wrote the below code. I wanted to see the document "/docs/first.json" only within this transaction. Basically, I wanted each statements within a server side JavasSript to see the updates of each other statements within the transaction and it shouldn't be visible outside the transaction. But when I ran the below code I got the document "/docs/first.json" which is the result of fn.doc("/docs/first.json"), which runs in the same transaction. But when I opened a new session and tried to fetch the document "/docs/first.json", I understood that the document had actually got ingested into the database and hence its visible outside the transaction as well.



      Can someone please correct where I am going wrong in this code so that I will be able to view the doc only within the transaction and not outside the transaction. I was able to achieve this using Xquery using ";" as statement separators.



      declareUpdate(explicitCommit: true);
      xdmp.eval('declareUpdate(); xdmp.documentInsert("/docs/first.json","first": 1);',commit:'explicit',transactionMode:'update')
      xdmp.eval('fn.doc("/docs/first.json")',transactionMode:"query")









      share|improve this question















      I wanted to check the transactional boundaries in Server-Side JavaScript in MarkLogic.



      So I wrote the below code. I wanted to see the document "/docs/first.json" only within this transaction. Basically, I wanted each statements within a server side JavasSript to see the updates of each other statements within the transaction and it shouldn't be visible outside the transaction. But when I ran the below code I got the document "/docs/first.json" which is the result of fn.doc("/docs/first.json"), which runs in the same transaction. But when I opened a new session and tried to fetch the document "/docs/first.json", I understood that the document had actually got ingested into the database and hence its visible outside the transaction as well.



      Can someone please correct where I am going wrong in this code so that I will be able to view the doc only within the transaction and not outside the transaction. I was able to achieve this using Xquery using ";" as statement separators.



      declareUpdate(explicitCommit: true);
      xdmp.eval('declareUpdate(); xdmp.documentInsert("/docs/first.json","first": 1);',commit:'explicit',transactionMode:'update')
      xdmp.eval('fn.doc("/docs/first.json")',transactionMode:"query")






      transactions marklogic serverside-javascript sjs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 5:03









      Mads Hansen

      43.3k1092119




      43.3k1092119










      asked Nov 9 at 15:06









      sharu

      264




      264






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          I believe the issue is that the explicit 'declareUpdate()' is overriding the xdmp.eval options which coerces it to an auto-commit. Furthermore you are mixing depricated with non-deprecated options. Dont mix xdmp.eval() options with the prolog -- something is committing the transaction. how you invoke the above code affects that as well.



          Please supply a complete example, this shows no 'commit' and you do not mention how you either invoked the above code or what you did to 'open a new session'.






          share|improve this answer




















          • If I am not giving declareUpdate() inside the eval function, it gives me the below error :
            – sharu
            2 days ago










          • [javascript] JS-DECLAREUPDATE: xdmp.documentInsert("/docs/first.json", ObjectNode("first":1)) -- JavaScript updates must begin with declareUpdate()
            – sharu
            2 days ago










          • Question above has my complete code which I am running from Query Console.I am not invoking this code from anywhere else. Also to 'open a new session' or transaction, I opened another Query console tab and checked for the document "/docs/first.json" using fn.doc function. But what I wanted to achieve is the eval function instead of autocomitting the eval code, it should be treated as another statement of the calling transaction, so that the document will be visible within the calling transaction but not anywhere outside the calling transaction if the transaction was a rollback
            – sharu
            2 days ago











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228277%2funderstanding-transaction-boundaries-in-server-side-javascript-marklogic%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          I believe the issue is that the explicit 'declareUpdate()' is overriding the xdmp.eval options which coerces it to an auto-commit. Furthermore you are mixing depricated with non-deprecated options. Dont mix xdmp.eval() options with the prolog -- something is committing the transaction. how you invoke the above code affects that as well.



          Please supply a complete example, this shows no 'commit' and you do not mention how you either invoked the above code or what you did to 'open a new session'.






          share|improve this answer




















          • If I am not giving declareUpdate() inside the eval function, it gives me the below error :
            – sharu
            2 days ago










          • [javascript] JS-DECLAREUPDATE: xdmp.documentInsert("/docs/first.json", ObjectNode("first":1)) -- JavaScript updates must begin with declareUpdate()
            – sharu
            2 days ago










          • Question above has my complete code which I am running from Query Console.I am not invoking this code from anywhere else. Also to 'open a new session' or transaction, I opened another Query console tab and checked for the document "/docs/first.json" using fn.doc function. But what I wanted to achieve is the eval function instead of autocomitting the eval code, it should be treated as another statement of the calling transaction, so that the document will be visible within the calling transaction but not anywhere outside the calling transaction if the transaction was a rollback
            – sharu
            2 days ago















          up vote
          1
          down vote













          I believe the issue is that the explicit 'declareUpdate()' is overriding the xdmp.eval options which coerces it to an auto-commit. Furthermore you are mixing depricated with non-deprecated options. Dont mix xdmp.eval() options with the prolog -- something is committing the transaction. how you invoke the above code affects that as well.



          Please supply a complete example, this shows no 'commit' and you do not mention how you either invoked the above code or what you did to 'open a new session'.






          share|improve this answer




















          • If I am not giving declareUpdate() inside the eval function, it gives me the below error :
            – sharu
            2 days ago










          • [javascript] JS-DECLAREUPDATE: xdmp.documentInsert("/docs/first.json", ObjectNode("first":1)) -- JavaScript updates must begin with declareUpdate()
            – sharu
            2 days ago










          • Question above has my complete code which I am running from Query Console.I am not invoking this code from anywhere else. Also to 'open a new session' or transaction, I opened another Query console tab and checked for the document "/docs/first.json" using fn.doc function. But what I wanted to achieve is the eval function instead of autocomitting the eval code, it should be treated as another statement of the calling transaction, so that the document will be visible within the calling transaction but not anywhere outside the calling transaction if the transaction was a rollback
            – sharu
            2 days ago













          up vote
          1
          down vote










          up vote
          1
          down vote









          I believe the issue is that the explicit 'declareUpdate()' is overriding the xdmp.eval options which coerces it to an auto-commit. Furthermore you are mixing depricated with non-deprecated options. Dont mix xdmp.eval() options with the prolog -- something is committing the transaction. how you invoke the above code affects that as well.



          Please supply a complete example, this shows no 'commit' and you do not mention how you either invoked the above code or what you did to 'open a new session'.






          share|improve this answer












          I believe the issue is that the explicit 'declareUpdate()' is overriding the xdmp.eval options which coerces it to an auto-commit. Furthermore you are mixing depricated with non-deprecated options. Dont mix xdmp.eval() options with the prolog -- something is committing the transaction. how you invoke the above code affects that as well.



          Please supply a complete example, this shows no 'commit' and you do not mention how you either invoked the above code or what you did to 'open a new session'.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 10 at 5:15









          DALDEI

          2,97488




          2,97488











          • If I am not giving declareUpdate() inside the eval function, it gives me the below error :
            – sharu
            2 days ago










          • [javascript] JS-DECLAREUPDATE: xdmp.documentInsert("/docs/first.json", ObjectNode("first":1)) -- JavaScript updates must begin with declareUpdate()
            – sharu
            2 days ago










          • Question above has my complete code which I am running from Query Console.I am not invoking this code from anywhere else. Also to 'open a new session' or transaction, I opened another Query console tab and checked for the document "/docs/first.json" using fn.doc function. But what I wanted to achieve is the eval function instead of autocomitting the eval code, it should be treated as another statement of the calling transaction, so that the document will be visible within the calling transaction but not anywhere outside the calling transaction if the transaction was a rollback
            – sharu
            2 days ago

















          • If I am not giving declareUpdate() inside the eval function, it gives me the below error :
            – sharu
            2 days ago










          • [javascript] JS-DECLAREUPDATE: xdmp.documentInsert("/docs/first.json", ObjectNode("first":1)) -- JavaScript updates must begin with declareUpdate()
            – sharu
            2 days ago










          • Question above has my complete code which I am running from Query Console.I am not invoking this code from anywhere else. Also to 'open a new session' or transaction, I opened another Query console tab and checked for the document "/docs/first.json" using fn.doc function. But what I wanted to achieve is the eval function instead of autocomitting the eval code, it should be treated as another statement of the calling transaction, so that the document will be visible within the calling transaction but not anywhere outside the calling transaction if the transaction was a rollback
            – sharu
            2 days ago
















          If I am not giving declareUpdate() inside the eval function, it gives me the below error :
          – sharu
          2 days ago




          If I am not giving declareUpdate() inside the eval function, it gives me the below error :
          – sharu
          2 days ago












          [javascript] JS-DECLAREUPDATE: xdmp.documentInsert("/docs/first.json", ObjectNode("first":1)) -- JavaScript updates must begin with declareUpdate()
          – sharu
          2 days ago




          [javascript] JS-DECLAREUPDATE: xdmp.documentInsert("/docs/first.json", ObjectNode("first":1)) -- JavaScript updates must begin with declareUpdate()
          – sharu
          2 days ago












          Question above has my complete code which I am running from Query Console.I am not invoking this code from anywhere else. Also to 'open a new session' or transaction, I opened another Query console tab and checked for the document "/docs/first.json" using fn.doc function. But what I wanted to achieve is the eval function instead of autocomitting the eval code, it should be treated as another statement of the calling transaction, so that the document will be visible within the calling transaction but not anywhere outside the calling transaction if the transaction was a rollback
          – sharu
          2 days ago





          Question above has my complete code which I am running from Query Console.I am not invoking this code from anywhere else. Also to 'open a new session' or transaction, I opened another Query console tab and checked for the document "/docs/first.json" using fn.doc function. But what I wanted to achieve is the eval function instead of autocomitting the eval code, it should be treated as another statement of the calling transaction, so that the document will be visible within the calling transaction but not anywhere outside the calling transaction if the transaction was a rollback
          – sharu
          2 days ago


















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228277%2funderstanding-transaction-boundaries-in-server-side-javascript-marklogic%23new-answer', 'question_page');

          );

          Post as a guest














































































          Popular posts from this blog

          Kleinkühnau

          Makov (Slowakei)

          Deutsches Schauspielhaus