Skip to content
Advertisement

How update and delete bulk operation in mongodb?

I’m building a taskmanagment application, where only admin can delete user. when admin delete a user, I want to assign deleted users task to the his assignby user.

JavaScript

when I delete devid user from the db I want to assign his task to the john and save the task

JavaScript

Advertisement

Answer

I think you are looking for transactions to avoid loss data.

So you can try somethig like (not real code):

JavaScript

If everything is ok, you commit the transaction and all changes are saved (also you can add some if an thorw an exception if you want), otherwise you can do a rollback and there is not any data loss.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement