The first class that needs to be defined is one that other domain service classes inherit from. The structure of this class is similar to the one shown earlier in this book. In this case, however, instead of requiring the calling program to define a MongoDB connection and supplying the connection to the constructor, we'll define a constructor that creates its own database and collection from the config.config.Config class described earlier in this book.
We'll start by defining the necessary import and class properties:
# booksomeplace.domain.base
from db.mongodb.connection import Connection
class Base :
db = None
collection = None
dbName = 'booksomeplace'
collectName = 'common'
As mentioned previously, the __init__() method creates an internal Connection, from which we can define database and collection properties:
def __init__(self, config) :
if config.getConfig('db') :
conn...