Indeed, you have a compilation error.
You should use db.getCollection("college") , which creates a collection if it does not exist.
In addition, a collection is created lazily when you add something to it.
You can add:
school.save(new BasicDBObject("key" , "value"));
Then a collection with one document will be created.
source share