title: Spring Data - MongoDB indexing DBRef
body: <p>I'm using spring-data-mongodb-1.2.0.RELEASE.
  I have two classes A and B where B has a reference to A and it is annotated with @DBRef.</p>
  <p>Class A:</p>
  <pre><code>@Document(collection = &quot;a&quot;)
  public class A {
  @Id
  public String id;
  
  /** The TicketGrantingTicket this is associated with. */
  @Field
  public String name;
  
  public A(String id, String name) {
      this.id = id;
      this.name = name;
  }
  }
  </code></pre>
  <p>Class B:</p>
  <pre><code>@Document(collection = &quot;b&quot;)
  public class B {
  
  @Id
  public String id;
  
  @Field
  public String name;
  
  @DBRef
  @Indexed
  public A a;
  
  public B(String id, String name, A a) {
      super();
      this.id = id;
      this.name = name;
      this.a = a;
  }
  }
  </code></pre>
  <p>Since I'm quering for all instances of B that are refering to a certain A:</p>
  <pre><code>B fromDB = mongoOperations.findOne(Query.query(Criteria.where(&quot;a.$id&quot;).is(a1.id)), B.class);
  </code></pre>
  <p>I need it to be indexed.</p>
  <p>After the first insertion of a B instance into MongoDB an index should be created.
  As can be seen below it doesn't:
  <img src="https://i.stack.imgur.com/58AHR.png" alt="" /></p>
  <p>Does anyone know how can I create such an index ?</p>
  <p>In addition it looks like the DBRef filed (as can be seen by the mongo shell) does not match to the format as it is defined at
  <a href="http://docs.mongodb.org/manual/applications/database-references/#format" rel="noreferrer">MongoDB documentation</a>.</p>
  <p>Am I missing something here?</p>