ming.datastore module¶
- class ming.datastore.DataStore(bind: Engine, name: str, encryption_config: encryption.EncryptionConfig = 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
Engineinstance.DataStores are usually created using the
create_datastore()function.- property db: Database¶
This is the database on MongoDB.
Accessing this property returns the pymongo db, untracked by Ming.
- decr(b: bytes | None) str | None¶
Decrypts a string using the encryption configuration of the ming datastore that this class is bound to.
- encr(s: str | None, _first_attempt=True, provider='local') bytes | None¶
Encrypts a string using the encryption configuration of the ming datastore that this class is bound to. Most of the time, you won’t need to call this directly, as it is used by the
ming.encryption.EncryptedDocumentMixin.encrypt_some_fields()method.
- make_data_key()¶
Mongodb’s Client Side Field Level Encryption (CSFLE) requires a data key to be present in the key vault collection. This ensures that the key vault collection is properly indexed and that a data key is present for each provider.
- class ming.datastore.Engine(Connection, conn_args, conn_kwargs, connect_retry, auto_ensure_indexes, _sleep=<built-in function sleep>)¶
Engine represents the connection to a MongoDB (or in-memory database).
The
Engineclass lazily creates the connection the first time it’s accessed.- property conn: Connection | MongoClient¶
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) DataStore¶
Creates a new
DataStorefor the database identified byuri.uriis a mongodb url in the formmongodb://username:password@address:port/dbname, it can also be used to connect to a replica set by specifying multiple mongodb addresses separated by comma setmongodb://localhost:27018,localhost:27019,localhost:27020/dbname?replicaSet=rsname.Optional Keyword args:
bind - a
ming.datastore.Engineinstance
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())