How to delete items in MongoRepository using query annotation?

后端 未结 6 1188
北海茫月
北海茫月 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:47

    Try this, it's work for me.

    @Repository
    public interface DepartmentDao extends MongoRepository {
        @DeleteQuery
        void deleteByDepartment(String department);
    }
    

    OR

    @Query(value="{'_id' : ?0}", delete = true)
    public void deleteById(String id);
    

提交回复
热议问题