MorphiaOrg / morphia

MongoDB object-document mapper in Java based on https://github.com/mongodb/mongo-java-driver
Apache License 2.0
1.65k stars 456 forks source link

Morphia and Indexes #2854

Closed vSKAH closed 8 months ago

vSKAH commented 8 months ago

Please ask your question and provide whatever background or supporting information you think might be relevant:

Hello I did this, however when I look in mongo compass the indexes do not appear. Do you have an idea?

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity(value = "player_battlepass")
@Indexes({
        @Index(fields = {@Field("player_id"), @Field("battlepass_id")}, options = @IndexOptions(unique = true, background = true, name = "player_battlepass_index")),
        @Index(fields = @Field("battlepass_id"), options = @IndexOptions(unique = true, background = true, name = "battlepass_id_index"))
})
public class PlayerBattlePass {

    @Id
    private int id;

    @Property("player_id")
    private UUID playerId;

    @Property("battlepass_id")
    private int battlePassId;

}

image

Server Version: MongoDB 5.0.24 Community Driver Version: 4.11.0 Morphia Version: 2.4.11

evanchooly commented 8 months ago

did you call datastore.ensureIndexes() ?