I want to abstract certain MongoDB queries/documents using classes.
Basically I think the way is to somewhere (an own class?) create the connection and use this connection(pool) in various Classes. But how would I do this code-wise. For example I am not sure, when I use a MongoDBConnectionClass and initialize the connection in the constructor how to make sure I wait for the connection to be established to continue using it somewhere else.
I think I am doing something wrong here. Here a schema to maybe better understand what I mean
MongoDBConnection(Class?)
+---- Class1+ # eg. Book
+---- Class2+ # eg. Library
+---- Class3+ # eg. Dust
|
+-- Library1+ # eg. New Book Release
+-- Library2+ # ...
+-- Library3+ # ...
|
+-- App1
+-- App2
+-- App3
Oh an CoffeScript answers would be great, but JS of course works as well.
I use this pattern in my tutorial (will be out soon)
https://github.com/christkv/tic-tac-toe-steps
If you look at the model and controllers I wrap the actual function with the db object.