Allow a Mongo repo to have a collection name specified

This commit is contained in:
Braydon 2023-12-16 18:13:06 -05:00
parent 71af157e3a
commit 7a168bbb05
2 changed files with 3 additions and 3 deletions

@ -124,7 +124,7 @@ public class MongoDB implements IDatabase<MongoClient, ConnectionString> {
if (!isConnected()) { // Not connected if (!isConnected()) { // Not connected
throw new IllegalStateException("Not connected"); throw new IllegalStateException("Not connected");
} }
return new MongoRepository<>(this, entityClass, database.getCollection(collectionName)); return new MongoRepository<>(this, entityClass, collectionName);
} }
/** /**

@ -36,9 +36,9 @@ public class MongoRepository<ID, E> extends Repository<MongoDB, ID, E> {
*/ */
@NonNull private final MongoCollection<Document> collection; @NonNull private final MongoCollection<Document> collection;
public MongoRepository(@NonNull MongoDB database, @NonNull Class<? extends E> entityClass, @NonNull MongoCollection<Document> collection) { public MongoRepository(@NonNull MongoDB database, @NonNull Class<? extends E> entityClass, @NonNull String collectionName) {
super(database, entityClass); super(database, entityClass);
this.collection = collection; collection = database.getDatabase().getCollection(collectionName); // Get the collection by the name
} }
/** /**