Unable to query data set from Mongo DB

I am getting the following exception while trying to fetch data from Mongo DB using a Java application.

String mongodbURL = env.getProperty("spring.data.mongodb.uri");
		 com.mongodb.client.MongoClient client = MongoClients.create( mongodbURL);

	        MongoDatabase mongoDatabase = client.getDatabase("EDD");
	        MongoCollection<org.bson.Document> coll = mongoDatabase.getCollection("ZipStoreDistanceData");
	        
		MongoCollection<StoreListForZip> zipCodeMongoCollection = mongoDatabase.getCollection("ZipStoreDistanceData",
				StoreListForZip.class);
		Bson filter = and(eq("_id", zipcode), lte("storeList.distanceInMiles", distance));		
		StoreListForZip storeListForZip = zipCodeMongoCollection.find(filter).first();

The line StoreListForZip storeListForZip = zipCodeMongoCollection.find(filter).first();
is the one which throws exception.
The exception is below

Caused by: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.blah.blah.dto.StoreListForZip```

my document looks like below in Mongo DB

{"_id":"US_00721","countryCode":"US","countryZip":"US_00721","storeList":[{"distanceInMiles":{"$numberInt":"20"},"storeNum":"11010"},{"distanceInMiles":{"$numberInt":"20"},"storeNum":"21111"},{"distanceInMiles":{"$numberInt":"17"},"storeNum":"31176"},{"distanceInMiles":{"$numberInt":"20"},"storeNum":"33060"},{"distanceInMiles":{"$numberInt":"17"},"storeNum":"51176"},{"distanceInMiles":{"$numberInt":"20"},"storeNum":"53060"}]}```

any insight into why the Java application is throwing this exception ?

my POJO class looks like below.

@Data
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class StoreListForZip {

	@JsonProperty("id")
	@Id
	String id;

	@JsonProperty("countryZip")
	String countryZip;

	@JsonProperty(value = "countryCode")
	String countryCode;

	@JsonProperty(value = "storeList")
	List<StoreDistance> storeList;

	

}```

Hi :wave: @ivin_jacob,

This error message is indicating that there is a problem with the MongoDB codec configuration for a class called “StoreListForZip”. The exception is saying that it can’t find a codec (i.e. a class responsible for encoding and decoding instances of the class to and from BSON) for this class. To resolve this issue, you need to either define your own decoding logic or use a different class that already has a codec registered.

For Quick Reference check out this article: Java - Mapping POJOs | MongoDB

Link to MongoDB Java Driver: Quick Start - POJOs

I hope it helps!

Best,
Kushagra