Embedded MongoDB With Spring Boot
Posted By : Vishal Kumar | 31-Jul-2018
While in the meantime making and testing Spring Boot applications with MongoDB as the data store, more often than not to use the lightweight Embedded MongoDB as opposed to running an obvious server. As the embedded MongoDB continues running in memory, it is impacting snappy and will save you package of time in the midst of both headways and when running your tests whether it's in your change machine or a CI server.
I have concealed setting MongoDB in a Spring Boot application here.
In this post, I'll talk about how to utilize installed MongoDB in a Spring Boot application.
The Maven Dependency
Installed MongoDB downloads and starts up a genuine MongoDB case. You get the advantage of conversing with an occurrence stacked in memory with an indistinguishable ability from your generation condition. The Maven POM reliance to incorporate Embedded MongoDB is this:
You additionally need to incorporate the
You have to give a MongoTemplate bean to Spring Boot for your application to collaborate with the inserted MongoDB occasion. You ordinarily utilize a @Configuration class, this way:
In this MongoConfig class, EmbeddedMongoFactoryBean is a FactoryBean for inserted MongoDB that runs MongoDB as an oversaw procedure and uncovered a pre-designed case of MongoClient.
This is all you have to do to begin utilizing Embedded MongoDB in a Spring Boot application.
Note: By default, your application will associate with the test database. For an alternate database, set the spring.data.mongodb.database property in your application.properties design document.