Is there a way to embed mongodb in the java application instead of running a daemon.
I have downloaded mongodb jdbc drivers and added them to classpath.
Is there a way to embed mongodb in the java application instead of running a daemon.
I have downloaded mongodb jdbc drivers and added them to classpath.
You can not embed mongodb in the java process. It is a separate process.
You can start and stop it when your program starts/stops by spawning the process. This is generally not suggested as mongodb is meant to run as a background server; if you do this is probably best you pick a random port to start it on so it doesn't affect any other mongodb instances. You will also need to make sure you include the correct binaries for the platform your java app is deployed on since it requires more than the JVM.
In java unit tests we can use Test Containers to spawn a Docker container with embedded MongoDB.
See autoconfiguration for Spring Boot projects: https://github.com/testcontainers/testcontainers-spring-boot#embedded-mongodb