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"})
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'.