Spring mongo软删除

时间:2016-06-28 12:17:01

标签: java spring spring-data-mongodb

我需要实现软删除功能(在表中维护一个布尔字段并根据此过滤所有查询)。 下面的链接只有hibernate的解决方案。 Handling soft-deletes with Spring JPA

由于我的应用程序已经过时,我不想更改每个现有查询。我正在寻找解决方案,如春季数据类中的一个地方更改。 Spring mongo数据版本:1.5.0.RELEASE

1 个答案:

答案 0 :(得分:0)

Add Boolean Field active to every class which is mapped with Collection
set the same true for all valid Documents  and false for non valid documnets 
private Boolean active = Boolean.TRUE;

and can chnage your Query to 
Long countByActiveTrueAndAccountStatusNot(AccountStatus status);