spring-projects / spring-projects/spring-data-mongodb
Easy access to Documents that are about to be deleted in BeforeDeleteEvent [DATAMONGO-2469]
@christophstrobl is already working on this.
Since Dec 30, 2020.
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
hoemich opened DATAMONGO-2469 and commented
While, with the BeforeSaveEvent it is very easy to get access to the Document that is about to be saved, in the BeforeSaveEvent it seems to be cryptic, and I failed to find any documentation on it.
To find out, what is about to be deleted, the only way I found was using
@EventListener
public void beforeDelete(BeforeDeleteEvent<MyDocument> event) {
List<ObjectId> event.getDocument()
.get("_id", Document.class)
.getList("$in", ObjectId.class);
// ... then use Ids to retrive the Document if necessary.
}
It would be great, to simplify this process, to get rid of cryptic identifiers, or if there is already another way, to provide documentation on it.
See also this question on SO: https://stackoverflow.com/questions/57149600/get-deleted-object-in-abstractmongoeventlistener/60153276#60153276
Affects: 2.2.4 (Moore SR4)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.