O'Reilly logo

Java 9: Building Robust Modular Applications by Jason Lee, Peter Verhas, Dr. Edward Lavieri

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required