springboot(java)操作mongodb删除数据 作者:马育民 • 2021-08-14 18:47 • 阅读:10101 上接:[springboot(java)操作mongodb创建工程](https://www.malaoshi.top/show_1IX1fPqX9Oje.html "springboot(java)操作mongodb创建工程") # junit 在 `/test/java` 下创建测试类: ``` @SpringBootTest public class Test { @Resource private MongoTemplate mt; //根据条件删除 @org.junit.jupiter.api.Test public void delete(){ Query q=Query.query(Criteria.where("id").is("cb0bcf1c425b47a9b7877c01cb2f0ded"));//查询全部 DeleteResult dr=mt.remove(q,User.class); System.out.println(dr.getDeletedCount()); } //根据id删除 @org.junit.jupiter.api.Test public void deleteById(){ User user=new User(); user.setId("8f38f06cbbf8463b852870edde0f43aa"); DeleteResult dr=mt.remove(user); System.out.println(dr.getDeletedCount()); } } ``` 原文出处:http://malaoshi.top/show_1IX1fx5AQgGe.html