Quantcast
Channel: Spring Community Forums - NoSQL
Viewing all articles
Browse latest Browse all 128

Indexing embedded document collection via @CompoundIndexes

$
0
0
I'm trying to index fields on an embedded collection and the indexes don't seem to be created. For example:

Code:


@Document
@CompoundIndexes({
        @CompoundIndex(name = "cred_idx", def = "{ 'credentials.provider': 1, 'credentials.providerUid': 1 }")
})
public class User {

        @Id
        private ObjectId id;
       
        @Field
        private String name;
       
        @Field
        private Set<Credential> credentials = new HashSet<Credential>();
}

public class Credential {

        private String provider;
       
        private String providerUid;
}

I want to index the Credential.provider and Credential.providerUid. If I put the annotation on the Credential class, then a Credential collection is made with the proper index. However, that doesn't get me anywhere.

Is there something I'm doing wrong, or do I need to do this by hand via the MongoTemplate?

Thanks.

Viewing all articles
Browse latest Browse all 128

Trending Articles