Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

MongoDb query in Java Spring

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...