This example demonstrates the integration of Mongo DB with Spring Boot. If you are running Mongo DB locally, then there is no need to configure anything for the Mongo database in the spring boot application.
Spring boot auto configures the mongo db configuration since by default mongo runs on
1) host - localhost or 127.0.0.1
2) port - 27017
If you are running a mongo db on local system, then you just have to configure the mongo repository interface in your spring boot application and use @EnableMongoRepositories annotation. Once you run the spring boot application you will notice a following log in your mongo db command prompt
This indicates that the spring boot application is connected to mongo db and you can perform db operations.
And once you stop the application you will observe
In any case there is a need for configuring the change in host or port, then perform following changes in application.properties file
Here is the maven dependency for spring data for mongo db
Spring Boot app java class - This class configures the spring controller file plus enables the mongo repository using @EnableMongoRepositories annotation.
Repository Interface - Mongo comes with the MongoRepository interface that internally performs all the basic db operations like insert, get & delete on its own. You must have to create a repository interface that extends MongoRepository interface along with the type. If you have mongo db data object Person then MongoRepository
Mongo Model class
Test Controller - Simply autowire the AppRepository object and start performing DB operations as shown below