Class Collection is used as a parent class that is representing our mongodb collection.
We will use this as a Model, that will communicate with our database and get all the data that we need. Also we will use this class for creating JSON that will be rendered on the client side. Moreover we can add here what ever we want, that is related with collection.
CollectionInstance is a child class that will represent our Instance collection.
CollectionType is a child class that will represent our Type collection.
I have changed this class a little bit. My idea was to make this class as a Singleton (Pattern). That means that we will always have only one instance of the class DB. We will always make our database one time, and then use it during the life of the app. Also I think tha t it is good to use patterns always when it is possible in order to have a good software architecture. Therefore we don't need database initialization on the beginning of the app (in the Global.java). Initialization will be done when the instance of our database is first time called.
As I have created a Singleton structure for our database, this class will not be needed anymore. But so far I think that we can use it in the future if we want to try to increase performance of the app.
Here I have only migrated all the code in the Collection class, so we have now a nice structure, all we need is to create a collection and get the JSON for rendering.