- Follow the same steps listed in the link above
- Do NOT use MySQL dependency
- Replace Spring Data JPA dependency w/ Spring Data MongoDB
- Download MongoDB: https://www.mongodb.com/try/download/enterprise
- For online MongoDB clusters, go to: https://account.mongodb.com/account/login
<!-- For REST API/web functionality -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Needed to connect to MongoDB (causes conflict w/ Spring Data JPA) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<!-- Reduce boiler plate code-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
// Class Based
@Data // constructor, getters, setters, equals, hashCode, toString
@Document // represents class as MongoDB document
// Field Based
@Id // primary key
- none
-
@Transactional
does not work w/ MongoDB. To update a document, you have to set the field and callsave(E e)
public interface ExampleRepository extends MongoRepository<ENTITY, ID>
{
// methods inherited from MongoRepository
}