i want to create collection in mongodb using java.The below is the code i worked with.I can connect to database.But Collection is not happening..please help me
import com.mongodb.MongoClient;
import com.mongodb.DB;
import com.mongodb.DBCollection;
public class CreateCollection{
public static void main( String args[] ){
try{
// To connect to mongodb server
MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
// Now connect to your databases
DB db = mongoClient.getDB( "cms" );
System.out.println("Connect to database successfully");
DBCollection school = db.createCollection("college");
System.out.println("Collection mycol created successfully");
}catch(Exception e){
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
}
}
}