httk.store.backend.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.backend.mongo.database.TransactionsUnavailableError

Bases: RuntimeError

An explicit transaction was requested without replica-set support.

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

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 | str) – 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.

property client: pymongo.MongoClient

Return the wrapped PyMongo client.

Returns:

The client that owns this database connection pool.

Return type:

pymongo.MongoClient

property database: Any

Return the selected PyMongo database handle.

Returns:

The PyMongo database handle.

Return type:

Any

property supports_transactions: bool

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()

Close the client and its connection pool.

Returns:

None.

Return type:

None