Now if the initial value of gender was empty "". Then after executing the above code, the final value should still be "" because the second update is invalid syntax and would throw exception.
There are a few things here. You need to pass the session into the operation as a transaction options. Otherwise the operation will be performed outside of a session. For example:
In addition, the update operation is structured with callbacks. In this case, what likely to happen is the first update was executed then the second thrown an exception.
If you’re using async functions, you could use await operator with a Promise to pause further execution until the Promise is resolved. You can do sequential logic execution in this manner, for example: