Connecting your application to MongoDB
In this recipe, we will learn how to deploy a MongoDB server in Docker. Next, we will create a Spring Boot application and connect it to our MongoDB server using Spring Data MongoDB. Finally, we will initialize the database and perform some queries against the data that’s been loaded.
We will use the scenario of football teams and players to demonstrate the different approaches to managing data in MongoDB compared to relational databases such as PostgreSQL.
Getting ready
For this recipe, we will use a MongoDB database. The easiest way to deploy it on your computer is by using Docker. You can download Docker from the product page at https://www.docker.com/products/docker-desktop/.
Once you have installed Docker, you can run a single instance of MongoDB or execute a cluster running in a replica set. Here, you will deploy a cluster running in a replica set. This is not necessary for this recipe but will be necessary for the following...