httk.store.mongo.database

MongoDB client lifecycle and transaction-mode probing.

Exceptions

TransactionsUnavailableError

An explicit transaction was requested without replica-set support.

Classes

MongoDatabase

A named MongoDB database reached through a wrapped PyMongo client.

Module Contents

exception httk.store.mongo.database.TransactionsUnavailableError[source]

Bases: RuntimeError

An explicit transaction was requested without replica-set support.

class httk.store.mongo.database.MongoDatabase(client, database, *, transactions='auto')[source]

A named MongoDB database reached through a wrapped PyMongo client.

The wrapper performs one hello probe when it is constructed. A replica-set name in that reply enables transaction mode unless the caller explicitly pins degraded mode.

Parameters:
  • client (pymongo.MongoClient) – The PyMongo client that owns the connection pool.

  • database (str) – The database name.

  • transactions (str) – "auto", "require", or "never".

Raises:

ValueError – If transactions is invalid or required transactions are unavailable.

classmethod connect(uri, *, database, transactions='auto')[source]

Connect to a MongoDB URI with durable majority defaults.

Parameters:
  • uri (str) – MongoDB connection URI.

  • database (str) – Database name to expose through the wrapper.

  • transactions (str) – "auto", "require", or "never".

Returns:

A connected database wrapper.

Raises:

ValueError – If the requested transaction mode is unavailable.

Return type:

Self

property client: pymongo.MongoClient[source]

Return the wrapped PyMongo client.

Returns:

The client that owns this database connection pool.

Return type:

pymongo.MongoClient

property database: Any[source]

Return the selected PyMongo database handle.

Returns:

The PyMongo database handle.

Return type:

Any

property supports_transactions: bool[source]

Whether this wrapper is configured to use MongoDB transactions.

Returns:

True when the mode probe found a replica set and the mode was not pinned to "never".

Return type:

bool

dispose()[source]

Close the client and its connection pool.

Returns:

None.

Return type:

None