Announcement Announcement Module
Collapse
No announcement yet.
Spring Data - MongoDB indexing DBRef Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data - MongoDB indexing DBRef

    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.

    Code:
        @Document(collection = "a")
        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:
        @Document(collection = "b")
        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;
    	}
        }
    Since I'm quering for all instances of B that are refering to a certain A:

    Code:
    B fromDB = mongoOperations.findOne(Query.query(Criteria.where("a.$id").is(a1.id)), B.class);
    I need it to be indexed.

    After the first insertion of a B instance into MongoDB an index should be created.
    As can be seen below it doesn't:
    Attachment

    Does anyone know how can I create such an index ?
    Attached Files

  • #2
    I am seeing the same issue.

    I was able to create the index manually, but I'd really prefer to have Spring/Mongo do it.

    Is this a known issue?

    Comment


    • #3
      Since non of the Spring guys replayed, I can't tell whether this issue is known or not.

      If you want a workaround you can find it here

      Comment

      Working...
      X