7

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

1 Answer 1

13

Use the in clause like this:

void deleteByIdIn(List<String> ids); 
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, thank you! Also, I have found one more way 'mongoTemplate.remove(new Query(Criteria.where("id").in(decisionAnalysisIds)), DecisionAnalysis.class);'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.