EK.
EK.

Reputation: 2996

Set index on embedded document in Mongodb

I use mongodb + springdata. My document looks like:

@Entity
@Document(collection="MyCollection")
public final class InfoItemMongoDBDocument {

    @Id
    private ObjectId id;

    @Column
    private String name;

    @Column
    @Indexed
    private int isFixed = 0;


    @Column
    private List<DocumentCopies> copy;

Where is DocumentCopies is POJO. Is it possible to set additional index on one of DocumentCopies field using Spring data annotations.

Thanks a lot!

Upvotes: 3

Views: 1050

Answers (1)

Neil Lunn
Neil Lunn

Reputation: 151122

Yes, you need a "dot notation" form referencing the field in your other POJO that is to be indexed:

@Document(collection="MyCollection")
@CompoundIndexes({
    @CompoundIndex( name="copy.childField", def="{'copy.childField': 1}")
})

Where "childField" is the name of your "field/property" that is being indexed.

Upvotes: 5

Related Questions