Quantcast
Viewing all articles
Browse latest Browse all 128

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:
tmp.jpg

Does anyone know how can I create such an index ?
Attached Images
  • Image may be NSFW.
    Clik here to view.
    File Type: jpg
    tmp.jpg (16.9 KB)

Viewing all articles
Browse latest Browse all 128

Trending Articles