1

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

luca
  • 3,248
  • 10
  • 66
  • 145

1 Answers1

0

I think you can do index 2 way. 1. @index in field you want 2. Do it programly

Please refer to this (Spring Data MongoDB - Where to create an index programmatically for a Mongo collection?)

because the collection is too big to use the deleteAll(), you are doing bigdata probblem so maybe this won't help.

Nam Nguyễn
  • 552
  • 4
  • 20