I'm using spring data to manage mongoDb collection and to remove all elements of some collections I'm using mongoTemplate.dropCollection(Anomaly.class);
because the collection is too big to use the deleteAll()
of CrudRepository.
The problem is the creation of the collection when a new document is added. The collection doesn't have the indexes (except the _id) despite the java class is correctly annotated:
@Field("anomaly_id")
@JsonProperty("anomaly_id")
@Indexed(unique = true)
private String anomalyId;
I tried with mongoTemplate.createCollection(Anomaly.class)
with the same result, but if I restart tomcat on the startup the collection is created with the indexes.
How can I fix this problem?Thanks