ming.datastore module

class ming.datastore.DataStore(bind, name, authenticate=None)

Represents a Database on a specific MongoDB Instance.

DataStore keeps track of a specific database on a MongoDB Instance, Cluster or ReplicaSet. The database is represented by its name while MongoDB is represented by an Engine instance.

DataStores are usually created using the create_datastore() function.

db

This is the database on MongoDB.

Accessing this property returns the pymongo db, untracked by Ming.

class ming.datastore.Engine(Connection, conn_args, conn_kwargs, connect_retry, sleep, auto_ensure_indexes)

Engine represents the connection to a MongoDB (or in-memory database).

The Engine class lazily creates the connection the firs time it’s actually accessed.

conn

This is the pymongo connection itself.

connect()

Actually opens the connection to MongoDB.

This is usually done automatically when accessing a database for the first time through the engine.

ming.datastore.create_datastore(uri, **kwargs)

Creates a new DataStore for the database identified by uri.

uri is a mongodb url in the form mongodb://username:password@address:port/dbname, it can also be used to connect to a replica set by specifying multiple mongodb addresses separated by comma set mongodb://localhost:27018,localhost:27019,localhost:27020/dbname?replicaSet=rsname.

Optional Keyword args:

  • bind - a ming.datastore.Engine instance
  • authenticate - a dict { name:str, password:str } with auth info

All other keyword args are passed along to create_engine().

The following are equivalent:

  • create_datastore(‘mongodb://localhost:27017/foo’)
  • create_datastore(‘foo’)
  • create_datastore(‘foo’, bind=create_engine())