Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature to undo/revert changes on a document (which haven't been persisted yet) #8714

Open
adamreisnz opened this issue Mar 24, 2020 · 3 comments
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class
Milestone

Comments

@adamreisnz
Copy link
Contributor

adamreisnz commented Mar 24, 2020

Do you want to request a feature or report a bug?
Feature request

What is the current behavior?
There is no easy way to revert changes to a document.

What is the desired behavior?
Something like:

const foo = mongoose
  .model('Foo')
  .find({_id});

console.log(foo); //{x: 2, y: 4}

foo.x = 6;
foo.y = 8;

console.log(foo); //{x: 6, y: 8}

foo.revert();

console.log(foo); //{x: 2, y: 4}

Use case
We have a use case where we update a document in preparation for saving, but then when payment fails, we don't proceed with the save. However, that document is then passed to an email to notify the user of the failure, but it will contain the modified data.

It'd be nice if there'd be an easy way to revert changes made on a document and revert back to the original values that were loaded from the database, thus preventing a re-fetch from the database or having to muck around with cloning objects.

@AbdelrahmanHafez
Copy link
Collaborator

@vkarpov15 I think this would be a great idea, do we currently store the old values of fields that have changed?

@vkarpov15
Copy link
Collaborator

Great idea. We do not currently store the old values of fields that have changed. But we need to in order to support reverting document state after a failed transaction (#8380) so I'll throw this into 6.0.

@vkarpov15 vkarpov15 added this to the 6.0 milestone Mar 28, 2020
@vkarpov15 vkarpov15 added enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class labels Mar 28, 2020
@adamreisnz
Copy link
Contributor Author

Cheers thanks guys

@vkarpov15 vkarpov15 modified the milestones: 6.0, Parking Lot Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class
Projects
None yet
Development

No branches or pull requests

3 participants