Using MongoDB with Spring Boot

Spring Boot is a powerful framework for building microservices. It comes ready to work with almost every type of database, including the newer NoSQL variety. This guide shows you how to quickly integrate MongoDB with your Spring Boot Application


Spring Boot has hundreds of starter packages that allow you to avoid writing code. They have a starter for mongodb as well. Include the following dependency:



Add your database connection string in the your configuration file: mongodb://localhost:27017/mongodb


Setup your entity model, just like you would for a traditional SQL entity

public class Permit {
    public String id;
    public String permitNum;
    public String revisionNum;
    public String permitType;
    public String structureType;
    public String work;
    public String streetNum;
    public String streetName;
    public String streetType;
    public String streetDirection;
    public String postal;

Setup Repository

public interface PermitRepository extends MongoRepository {
    List findAll();

That’s it! you can start using your Model to GET or POST data from your MongoDB Database

Author: Dev

Full Stack Developer at one of the largest Banks in Canada.