how to drop collection in mongodb using java


how to drop collection in mongodb using java

import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.MongoClient;

public class DropCollection {
     public static void main(String args[]) {
        try {
            //Connect to mongodb with port number
            MongoClient mongoClient = new MongoClient("localhost", 27017);
            //Here test is Database name of mongodb
            DB db = mongoClient.getDB("test");
            //Here Stud is a collection name that we want to create
            DBCollection dBCollection = db.getCollection("Stud");
            dBCollection.drop();
            System.out.println("Collection Droped");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}






Full-stack web and mobile app development company Contact Us : Skype: indore.webcoder Email: info@w3sparks.com Sales: +91 8085506229