Reputation: 193
I'm using firebase for node, and when attempting to use transaction to create store data, I get:
[Error: Set]
I'm having a hard time figuring out what this error code is suggesting. I've re-written my code, temporarily disabled security rules, but I get the same error.
Here's the code I'm using:
myRef.child(user).transaction(function(currentData) {
if (currentData === null) {
//data doesn't exist
return {
total: userTotal,
left: userLeft,
isText: userIsText
};
} else {
currentData.total += userTotal;
currentData.left += userLeft;
return {
total: currentData.total,
left: currentData.left,
isText: currentData.isText
};
}
}, function(error, committed, snapshot) {
if(error) {
console.log('@line 281: FB Tx failed', error);
} else if (!committed) {
console.log('FB Tx aborted');
}
});
the actual console error message that I get, of course, is:
@line 281: FB Tx failed [Error: Set]
Any insight on what kind of error the error code is supposed to signify/what is going wrong in the code? I have almost identical piece of code elsewhere in the script, which actually works, so I'm very puzzled...
Thanks in advance!
Upvotes: 2
Views: 1305
Reputation: 13266
The error you're seeing is indicating that the transaction is being aborted due to a write elsewhere in your app / code.
Firebase transactions work by applying a local transformation function to the current state of the data and writing the new state to the server. However, if you have a call to ref.set(...)
, ref.update(...)
, or ref.remove()
for the same path elsewhere in your code, you're going to clobber the change at that path anyway, which is why the transaction is aborted.
If you're having trouble tracking down the changes at that path, try using Firebase.enableLogging(true)
at the start of your app to see what the Firebase client is doing under the hood.
Upvotes: 8