Aug 3rd, 2012, 05:24 AM
Drop MongoDB collection using MongoTemplate or MongoOperation from Spring-data
I have a Catalog class mapped to MongoDB collection using Spring-data. I have created an unique index for "name" property for Catalog using Annotation. Before every test begun, I dropped Catalog collection and recreate again. What I observed was the unique index was created when MongoTemplate during Spring injection. Next, when I executed dropCollection() on Catalog, index was dropped. This was confirmed when I read org.springframework.data.mongodb.core.MongoTemplat e.java
My question is how do I preserve the collection unique index annotated in Catalog other than using MongoTemplate.remove(...) instead of dropCollection() or re-create the index explicitly using ensureIndex(...) ?
I have posted the same question in StackOverflow.
Tags for this Thread