As so many people before me on stackoverflow I want to do junit-tests for my mongodb application. For this I let an instance run, so my tests can connect. But I want to ensure that the database is in an empty state when starting to test.
Since I'm using spring-mongodb, spring-test and all the funny spring-things I hoped to find a configuration that does this for me, until now successless.
Can anybody give me a hint how to implement this in a clean way. My idea is a InitializingBean that does this for me. But I'm not really happy with ths solution. Any suggestions?
Try this:
@Autowired
org.springframework.data.mongodb.core.MongoTemplate mongoTemplate;
.....
mongoTemplate.getDb().dropDatabase();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With