could someone please, provide an example of a rollback operation with feathersjs and mongoose. from a hook? thank you
//hook befor
hook.app.service('service1').update(data).then(data1Save =>
{
hook.app.service('service2').update(data2).catch(err=>{
// TODO rollback service1
});
});
There is no rollback in feathersjs, that construct is dependent of the data provider, and would need to be integrated manually most likely.
What I generally do is perform my updates on the edge components, then I update the dependent components after the edge items exist.
If you keep a list of the edge items within the dependent Item it will allow you to perform cleanup afterwards to ensure the updates went in.
// Example
app.service('transaction').create({...transactionInfo}).then(createdTransaction => {
app.service('account').update(accountId,
{
$addToSet:{
transactions:[createdTransaction._id] // add id to the parent
},
$set:{
// nonTransactionsListdata
}
}
).then(updatedAccount => {
// All updates should be successful
// you can check to see if they took effect and resolve accordingly
}).catch( err => {
//Something happened, and may require a retry.
// check validity of createdTransaction to ensure its being used correctly
});
}).catch(err => {
// Issue creating the transaction in the first place
});