Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data MongoDB repository method delete by list of id

I have the following document:

@Document(collection = "decision_analysis")
public class DecisionAnalysis implements Serializable {

    @Id
    private String id;

...

}

I need to delete multiple MongoDB documents via List<String> decisionAnalysisIds

How to properly write Spring Data MongoDB repository method in order to do it?

The following doesn't work :

void deleteByIds(List<String> decisionAnalysisIds); - error: No property ids found for type DecisionAnalysis! Did you mean 'id'?

void deleteById(List<String> decisionAnalysisIds); - works, but delete only one document

like image 316
alexanoid Avatar asked Sep 09 '17 19:09

alexanoid


1 Answers

Use the in clause like this:

void deleteByIdIn(List<String> ids);
like image 187
Daniel C. Avatar answered Oct 25 '22 21:10

Daniel C.