0

I am trying to query based on Object attributes combination in MongoDB:

My Object looks like:

@Getter
@Setter
class Person {
    private String name;
    private String email;
    private Address address;
}

Address entity looks like:

@Getter
@Setter
class Address {
    private String city;
    private String state;
    private String postal;
    private String country;
}

Assume that above classes are also annotated with necessary attributes required for MongoDB collections.

Now when I am about to query from a PersonRepo interface that extends MongoRepository, as:

public interface PersonRepo extends MongoRepository<Person, String> {
    
}

The objective is to fetch all result-set where Address matches any combination of city, state, postal or country. For example, I want to fetch all results where city=XYZCity, state = ABCState, Postal might not be provided and country might be DEFCountry.

Address can be in any combination and whatever combination matches, the result-set could be produced.

3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.