Automattic / Automattic/mongoose
Feature to undo/revert changes on a document (which haven't been persisted yet)
- Dominant language
- JavaScript
- Stars
- 27.5k
- Forks
- 4k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 35
Description
**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:
```js
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.
Contributor guide
Research direction
The issue names no files, tests, or entry points. Start by reading Mongoose's document API and change-tracking behavior, then determine how an undo operation should restore values loaded from the database and how completion would be verified without saving or re-fetching.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb
- Domain
- backend, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100