我想使用java在mongodb中创建集合。下面是我使用的代码。我可以连接到数据库。但是集合没有发生..请帮助我
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() );
}
}
}