I have the following code:
if (user.getNationalities() != null && !user.getNationalities().isEmpty()) {
query.addCriteria(Criteria.where("filters.nationalities").in(user.getNationalities())
.orOperator(Criteria.where("filters.nationalities").exists(false)));
} else {
query.addCriteria(Criteria.where("filters.nationalities").exists(false));
}
The problem is, when I add subquery where nationalities are in user.getNationalities() or are otherwise empty, I got 0 results. When I do them separately, they work properly. How can I make them work together? It cannot be done in another way. How can I make this work?
public class Filters {
private Integer minAge;
private Integer maxAge;
private List<Nationality> nationalities;
private List<ReligionFilter> religions;
private Boolean hijab;
private MartialStatus martialStatus;
Nationality is an enum
question from:
https://stackoverflow.com/questions/65850274/mongodb-query-in-java-spring 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…