I'm fetching records of around 1200 records, if I query it from Mongo Compass, it uses the Compound Index which I created, and from 20ms(without indexing) to 0ms the performance shows, but If I use the same query in my Spring Boot Java project using Document class and using the below query, it takes up to 2 secs to fetch the same record.
To create indexes I used to db.collectionName.createIndex()
Below is the Java Spring Data Query
@Query(value="{country:?0, age: ?1}",fields="{'name':1,'state':1}")
public List<Object> getcountrySpecificName(String country, String name);