Reputation: 17697
I would like to dropDatabase in my mongo before my integration tests. Is it possible to do this through spring mongo ?
If it's not available for now, is it possible on fetching the com.mongodb.DB object somehow from spring mongo, so i can invoke it's dropDatabase() ?
Upvotes: 3
Views: 2800
Reputation: 1089
Just in case someone needs the info, notice that since 3.0 there is no dropDatabase() method in the MongoDatabase api, so you have to write this instead:
mongoTemplate.getDb().drop();
Upvotes: 5
Reputation: 2296
A slightly cleaner solution which I am using is to use the MongoDbFactory object, as below:
mongoDbFactory.getDb().dropDatabase();
Upvotes: 3
Reputation: 17697
Found it at last !
From mongodb shell :
> db.dropDatabase
function () {
if (arguments.length) {
throw "dropDatabase doesn't take arguments";
}
return this._dbCommand({dropDatabase:1});
}
combined with mongoOperations' executeCommand :
@Autowired private MongoOperations ops;
@BeforeMethod
public void dropDb() {
this.ops.executeCommand("{dropDatabase:1}");
}
Upvotes: 1