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")
transactions marklogic serverside-javascript sjs
add a comment |
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")
transactions marklogic serverside-javascript sjs
add a comment |
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")
transactions marklogic serverside-javascript sjs
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
transactions marklogic serverside-javascript sjs
edited Nov 10 at 5:03
Mads Hansen
43.3k1092119
43.3k1092119
asked Nov 9 at 15:06
sharu
264
264
add a comment |
add a comment |
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'.
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
add a comment |
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'.
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
add a comment |
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'.
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
add a comment |
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'.
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'.
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password