根据除 _id 以外的字段进行删除,可以使用自定义的查询方法来实现。可以在自定义的查询方法中使用 MongoDB 的查询语法来指定删除条件,从而根据其他字段进行删除。
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
public interface MyRepository extends MongoRepository<MyDocument, String> {
@Query("{ 'fieldName' : ?0 }")
void deleteByFieldName(String fieldName);
}
MongoRepository 默认的删除方法是根据 _id 字段进行删除的,根据除 _id 以外的字段进行删除,可以使用自定义的查询方法来实现。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有