How to delete items in MongoRepository using query annotation?

后端 未结 6 1195
北海茫月
北海茫月 2021-02-05 06:03

I\'m using Spring Data with MongoDB using MongoRepository.

I was wondering if it is possible do a delete by filter using query annotation. I have been looking here and g

6条回答
  •  故里飘歌
    2021-02-05 06:53

    Maybe you can use repository delete queries. Here is an example from documentation:

    public interface PersonRepository extends MongoRepository {
      List  deleteByLastname(String lastname);
    
      Long deletePersonByLastname(String lastname);         
    }
    

    Using return type List will retrieve and return all matching documents before actually deleting them. A numeric return type directly removes the matching documents returning the total number of documents removed.

提交回复
热议问题