title: Spring Boot MongoDb Collections
body: <p>I am pretty new to mongo so this is probably just me not understanding how to setup collections. I have 2 domain objects and I have stripped them down to the basics for simplicity.</p>
  
  <p><strong>Post.java</strong></p>
  
  <pre><code>@Document
  public class Post {
  
      @Id
      private BigInteger id;
  
      private String title;
  
      private String body;
  
      private String teaser;
  
      private String slug;
  
      private Date postedOn;
  
      private Author author;
  
      public Post(){
  
      }
  
      // getters &amp; setters
  
  }
  </code></pre>
  
  <p><strong>Author.java</strong></p>
  
  <pre><code>@Document
  public class Author {
  
      private BigInteger id;
      private String firstName;
      private String lastName;
      private String email;
  
      @DBRef
      private List&lt;Post&gt; posts;
  
      public Author(){
  
      }
  
      // getters and setters 
  
  }
  </code></pre>
  
  <p>I have a method that gets called to load some data into the database. </p>
  
  <pre><code>@PostConstruct
  private void initDatabase(){
  
      authorRepository.deleteAll();
  
      Author dv = new Author();
      dv.setFirstName("Dan");
      dv.setLastName("Vega");
      dv.setEmail("danvega@gmail.com");
      authorRepository.save( dv );
  
      postRepository.deleteAll();
  
      Post post = new Post();
      post.setTitle("Spring Data Rocks!");
      post.setSlug("spring-data-rocks");
      post.setTeaser("Post Teaser");
      post.setBody("Post Body");
      post.setPostedOn(new Date());
      post.setAuthor(dv);
      postRepository.save(post);
  
  }
  </code></pre>
  
  <p>When I run mongo from the console and show collections I see both the post and author collections. </p>
  
  <p>When I run db.post.find() the post contains the author object</p>
  
  <pre><code>{ "_id" : ObjectId("5666201fd4c6bcfd2f4caa90"), "_class" : "com.therealdanvega.domain.Post", "title" : "Spring Data Rocks!", "body" : "Post Body", "teaser" : "Post Teaser", "slug" : "spring-data-rocks", "postedOn" : ISODate("2015-12-08T00:11:11.090Z"), "author" : { "_id" : ObjectId("5666201fd4c6bcfd2f4caa8f"), "firstName" : "Dan", "lastName" : "Vega", "email" : "danvega@gmail.com" } }
  </code></pre>
  
  <p>But when I run db.author.find() I don't see the post collection in there. </p>
  
  <pre><code>{ "_id" : ObjectId("5666201fd4c6bcfd2f4caa8f"), "_class" : "com.therealdanvega.domain.Author", "firstName" : "Dan", "lastName" : "Vega", "email" : "danvega@gmail.com" }
  </code></pre>
  
  <p>Does anyone know what I am missing? </p>