No SQL > Mongo DB > How to remove all Documents in a Collection
How to remove all Documents in a Collection
MongoDB is a scalable, high-performance, open source NoSQL database.
It offers Ad hoc queries, Indexing, Replication, Load balancing, File storage (GridFS), Aggregation,
MapReduce and Server-side JavaScript execution.
This requires the library mongo-2.8.0.jar to be present in the classpath.
The following example shows how to remove all documents in a Collection.
private static void listAll(DBCollection collection) {
//Queries for all objects in this collection
DBCursor dbCursor = collection.find();
DBObject record = null;
while (dbCursor.hasNext()) {
record = dbCursor.next();
System.out.println(record);
}
}
}