To get started with connecting to MongoDB, include the dependency for Spring Boot MongoDB starter in the pom.xml:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency>
Let's create a new Entity class Person to store to MongoDB. The following snippet shows a Person class with an ID and a name:
public class Person { @Id private String id; private String name; public Person() {// Make JPA Happy } public Person(String name) { super(); this.name = name; } }
We would want to store the Person entities to MongoDB. We would need to create a ...