Is there a single method from MongoDB Java driver which deletes all documents in a collection ? so far I've only been able to do this by browsing a cursor and calling delete on each Document. Thanks
Asked
Active
Viewed 1,261 times
-1

Marc
- 3,683
- 8
- 34
- 48

user2824073
- 2,407
- 10
- 39
- 73
-
3use the `collection.drop()` method on the `DBCollection` object. – chridam Mar 31 '15 at 14:33
1 Answers
2
You can use :
MongoClient mongoClient = new MongoClient();
DB db = mongoClient.getDB("dbName");
DBCollection myCollection = db.getCollection("collectionName");
myCollection.drop();

Vishwas
- 6,967
- 5
- 42
- 69