diff --git a/core/src/main/java/dev/morphia/DatastoreImpl.java b/core/src/main/java/dev/morphia/DatastoreImpl.java index 0f03133fa91..44ae8d633d1 100644 --- a/core/src/main/java/dev/morphia/DatastoreImpl.java +++ b/core/src/main/java/dev/morphia/DatastoreImpl.java @@ -146,6 +146,7 @@ public DatastoreImpl(DatastoreImpl datastore) { this.queryFactory = datastore.queryFactory; this.operations = datastore.operations; codecRegistry = buildRegistry(); + this.database = this.database.withCodecRegistry(this.codecRegistry); } private CodecRegistry buildRegistry() { @@ -345,8 +346,7 @@ public MongoCollection getCollection(Class type) { EntityModel entityModel = mapper.getEntityModel(type); String collectionName = entityModel.getCollectionName(); - MongoCollection collection = getDatabase().getCollection(collectionName, type) - .withCodecRegistry(codecRegistry); + MongoCollection collection = getDatabase().getCollection(collectionName, type); Entity annotation = entityModel.getEntityAnnotation(); if (annotation != null && !annotation.concern().equals("")) {