title: How to get data with referenced object in Spring data mongo?
body: <p>This is <code>City</code> document class which i used.</p>
  
  <pre><code>@Document("city")
  public class City {
      @Id
      private String id;
      @Indexed(unique = true)
      private String name;
      @DBRef(lazy = true)
      private District district;
  
      public City() {
      }
  
      public City(String id) {
          this.id = id;
      }
  
      public City(String id, String name, District district) {
          this.id = id;
          this.name = name;
          this.district = district;
      }
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public District getDistrict() {
          return district;
      }
  
      public void setDistrict(District district) {
          this.district = district;
      }
  }
  </code></pre>
  
  <p>and this is the <code>District</code> document class</p>
  
  <pre><code>@Document("district")
  public class District {
      @Id
      private String id;
      @Indexed
      private String name;
  
      public District() {
      }
  
      public District(String id) {
          this.id = id;
      }
  
      public District(String id, String name) {
          this.id = id;
          this.name = name;
      }
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p>and this is the <code>district</code> collection data.</p>
  
  <pre><code>/* 1 */
  {
      "_id" : ObjectId("5d9482f3ff7ab743f0542070"),
      "name" : "Ampara",
      "_class" : "com.test.sample.model.District"
  }
  
  /* 2 */
  {
      "_id" : ObjectId("5d9482f3ff7ab743f0542071"),
      "name" : "Anuradhapura",
      "_class" : "com.test.sample.model.District"
  }
  </code></pre>
  
  <p>and this is the <code>city</code> collection data.</p>
  
  <pre><code>/* 1 */
  {
      "_id" : ObjectId("5d948333ff7ab743f0542089"),
      "name" : "Polgampola",
      "district" : {
          "$ref" : "district",
          "$id" : ObjectId("5d9482f3ff7ab743f0542070")
      },
      "_class" : "com.test.sample.model.City"
  }
  
  /* 2 */
  {
      "_id" : ObjectId("5d948333ff7ab743f054208a"),
      "name" : "Porawagama",
      "district" : {
          "$ref" : "district",
          "$id" : ObjectId("5d9482f3ff7ab743f0542070")
      },
      "_class" : "com.test.sample.model.City"
  }
  
  /* 3 */
  {
      "_id" : ObjectId("5d948333ff7ab743f054208b"),
      "name" : "Akkaraipattu",
      "district" : {
          "$ref" : "district",
          "$id" : ObjectId("5d9482f3ff7ab743f0542071")
      },
      "_class" : "com.test.sample.model.City"
  }
  </code></pre>
  
  <p>this is the repository class for the above city document class</p>
  
  <pre><code>@Repository
  public interface CityDao extends MongoRepository&lt;City,String&gt; {
      List&lt;City&gt; findByDistrict(String id);
  }
  </code></pre>
  
  <p>in the city class, i have used referenced document class called <code>District</code>. this a another document. I need to get the cities which belong to one district. <code>findByDistrict(String id)</code> method doesn't return values. Its just returning empty <code>List</code>. So How can i do this ?</p>