Allow a Mongo repo to have a collection name specified
This commit is contained in:
parent
71af157e3a
commit
7a168bbb05
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user