Adding MongoDB

In the body of the method, we get our first glimpse of the integration with MongoDB. To make this compile, we need to add a dependency on the MongoDB Java Driver:

    <dependency> 
      <groupId>org.mongodb</groupId> 
      <artifactId>mongodb-driver</artifactId> 
      <version>3.4.2</version> 
    </dependency> 

MongoDB deals with documents, so we need to convert our domain model to a Document, which we accomplish via a method on our model class. We haven't looked at the details of the Note class, so let's do that now:

 public class Note { private String id; private String userId; private String title; private String body; private LocalDateTime created = LocalDateTime.now(); private LocalDateTime modified = null; // Getters, setters and some constructors ...

Get Java 9: Building Robust Modular Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.