eugenp / tutorials

Just Announced - "Learn Spring Security OAuth":

Home Page:http://bit.ly/github-lsso

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mongodb spring.data.mongodb.auto-index-creation not working

seqwait opened this issue · comments

the spring-boot mongo config

@CompoundIndexes({
  @CompoundIndex(def = "{'to': 1, 'sendTime': 1}"),
  @CompoundIndex(def = "{'from': 1, 'sendTime': 1}"),
  @CompoundIndex(def = "{'from': 1,'to': 1, 'sendTime': 1}")
})
@Document("#{@mongoColName.message()}")
public class MongoMessage implements Serializable {
  @Field(targetType = FieldType.INT64)
   public String id;
   public String to;
   public String from;
   public Date sendTime;
}

it looks like, when a new collection is created CompoundIndex does not create it must restart the application
how resolve it?

Hey, @seqwait!

This is by design: https://docs.spring.io/spring-data/mongodb/docs/current-SNAPSHOT/reference/html/#mapping.index-creation

"Indexes are automatically created for the initial entity set on application startup and when accessing an entity type for the first time while the application runs."