user2924127 user2924127 - 1 year ago 119
Node.js Question

gcloud Datastore transaction issue using nodejs

I am using nodejs to contact the google datastore. This is my code:

dataset.runInTransaction(function(transaction, done,err) {
// From the `transaction` object, execute dataset methods as usual.
// Call `done` when you're ready to commit all of the changes., function(err) {

console.log("ERROR TRNASCTION");
console.log("TRANSACTION SUCCESS!");



If the save was not successful, I would like the transaction to rollback and if it was I want it to commit. The problem I am facing is that neither of them seem to be running, just no output on the console. Nothing is being sent to my database so I would assume at least the 'if(err)' condition would run but it doesn't. I am new to glcoud so I am not sure if I am doing something wrong here? I am following the doc at

Answer Source

In the context of a transaction, the save method doesn't actually need a callback. The things you wish to save are queued up until you call done(). Calling done will commit the transaction.

You can then handle errors from the commit operation in a second function passed to runInTransaction. See for examples of that.


Just mentioning this since it relates to the rollback part: -- we're waiting on an upgrade to Datastore's API before tackling that issue.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download