Package com.project.system
Class MongoDBUtil
java.lang.Object
com.project.system.MongoDBUtil
The
MongoDBUtil
class provides utility methods to start an embedded MongoDB server,
establish a connection, and access the MongoDB database.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static com.mongodb.client.MongoClient
The MongoDB client used to connect to the database.private static de.flapdoodle.embed.mongo.MongodExecutable
The executable for the embedded MongoDB instance. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
close()
Closes the MongoDB client connection and stops the embedded MongoDB server.static com.mongodb.client.MongoDatabase
Starts the embedded MongoDB server and establishes a connection to the MongoDB instance.
-
Field Details
-
mongodExecutable
private static de.flapdoodle.embed.mongo.MongodExecutable mongodExecutableThe executable for the embedded MongoDB instance. -
mongoClient
private static com.mongodb.client.MongoClient mongoClientThe MongoDB client used to connect to the database.
-
-
Constructor Details
-
MongoDBUtil
public MongoDBUtil()
-
-
Method Details
-
getDatabase
public static com.mongodb.client.MongoDatabase getDatabase()Starts the embedded MongoDB server and establishes a connection to the MongoDB instance.- Returns:
- The
MongoDatabase
instance connected to the "student_course_db" database. - Throws:
RuntimeException
- if MongoDB fails to start.
-
close
public static void close()Closes the MongoDB client connection and stops the embedded MongoDB server.
-