Skip to content
Packages Examples Agents Blog Get started

NoSQL document store support for the Oridecon Framework (MongoDB, DynamoDB, Firestore).


oridecon-nosql provides async document-store backends behind a clean protocol interface. It ships with a MongoDB driver (Motor-based), a fluent query builder, aggregation pipelines, the repository pattern with specifications, a migration manager, and Named DI multi-backend support. The MongoDB driver is registered through the container; DynamoDB and Firestore backends are available as direct-use classes (oridecon.nosql.backends.dynamodb, oridecon.nosql.backends.firestore).


Full documentation: docs.oridecon.dev

Terminal window
uv add oridecon oridecon-nosql
# With MongoDB support
uv add "oridecon-nosql[mongodb]"
# With DynamoDB support
uv add "oridecon-nosql[dynamodb]"
# With Firestore support
uv add "oridecon-nosql[firestore]"
from oridecon import Application
from oridecon.di.module import Module, module
from oridecon.nosql import NoSQLModule
from oridecon.nosql.config import MongoDBConfig, NoSQLConfig
from oridecon.contracts.data.nosql.nosql import DocumentStoreProtocol
@module(
imports=[
NoSQLModule.configure(
NoSQLConfig(
driver="mongodb",
mongodb=MongoDBConfig(
uri="mongodb://localhost:27017",
database="myapp",
),
)
)
]
)
class AppModule(Module):
pass
async def main() -> None:
async with Application.boot(modules=[AppModule]) as app:
store = await app.container.resolve(DocumentStoreProtocol)
collection = store.collection("users")
await collection.insert_one({"name": "Alice", "age": 30})
async for user in collection.find({"age": {"$gte": 25}}):
print(user)
if __name__ == "__main__":
import asyncio
asyncio.run(main())

Zero-config usage: Call NoSQLModule.configure() with no arguments to use all defaults.

application.yaml
nosql:
driver: "mongodb"
mongodb:
uri: "mongodb://localhost:27017"
database: "myapp"
max_pool_size: 100
Section titled “Option 2 — Profiles + Environment Variables (recommended)”
Terminal window
export ORI_NOSQL__DRIVER=mongodb
export ORI_NOSQL__MONGODB__URI=mongodb://localhost:27017
export ORI_NOSQL__MONGODB__DATABASE=myapp
from oridecon.nosql import NoSQLModule
from oridecon.nosql.config import NoSQLConfig, MongoDBConfig
NoSQLModule.configure(
NoSQLConfig(
driver="mongodb",
mongodb=MongoDBConfig(uri="mongodb://localhost:27017", database="myapp"),
)
)

NoSQLConfig

FieldDefaultEnv varDescription
enabledtrueORI_NOSQL__ENABLEDEnable NoSQL support
driver"mongodb"ORI_NOSQL__DRIVERNoSQL driver ("mongodb"; only MongoDB is module-wired today — DynamoDB/Firestore backends are direct-use classes)
mongodbMongoDBConfig()MongoDB-specific connection configuration
backends[]Named backend entries for multi-backend DI registration

MongoDBConfig

FieldDefaultEnv varDescription
uri"mongodb://localhost:27017"ORI_NOSQL__MONGODB__URIMongoDB connection URI
database"oridecon"ORI_NOSQL__MONGODB__DATABASEDatabase name
max_pool_size100ORI_NOSQL__MONGODB__MAX_POOL_SIZEMaximum connection pool size
min_pool_size10ORI_NOSQL__MONGODB__MIN_POOL_SIZEMinimum connection pool size
retry_writestrueORI_NOSQL__MONGODB__RETRY_WRITESEnable write retries
retry_readstrueORI_NOSQL__MONGODB__RETRY_READSEnable read retries
read_preference"primaryPreferred"ORI_NOSQL__MONGODB__READ_PREFERENCERead preference mode
write_concern_w"majority"ORI_NOSQL__MONGODB__WRITE_CONCERN_WWrite concern level
auth_source"admin"ORI_NOSQL__MONGODB__AUTH_SOURCEAuthentication database
MethodDescription
NoSQLModule.configure(config)Configure with explicit config
NoSQLModule.scope(*repositories)Scope repository classes into a feature module
NoSQLModule.stub()Minimal config for testing
  • MongoDB backend — async Motor-based with connection pooling and retry logic
  • Query builder — type-safe fluent API for MongoDB queries and projections
  • Aggregation pipelines — composable pipeline stages for complex aggregations
  • Repositories — base DocumentRepository pattern with specification support
  • Migration manager — index creation, field operations, and collection management
  • Named DI multi-backend — multiple backends registered via Annotated[DocumentStoreProtocol, Named("analytics")]
  • Session and transaction context managersmongodb_session() and mongodb_transaction() (oridecon.nosql.backends.mongodb.session) for ACID operations

oridecon-nosql ships no in-memory backend — stub() uses the MongoDB driver, so boot requires a reachable MongoDB. Point it at a test instance:

from oridecon.nosql.config import MongoDBConfig, NoSQLConfig
config = NoSQLConfig(
driver="mongodb",
mongodb=MongoDBConfig(uri="mongodb://localhost:27017", database="testdb"),
)
async with Application.boot(modules=[NoSQLModule.stub(config)]) as app:
store = await app.container.resolve(DocumentStoreProtocol)
collection = store.collection("users")
await collection.insert_one({"name": "Alice"}) # requires a live test MongoDB
FileWhat it contains
src/oridecon/nosql/module.pyNoSQLModule.configure(), .scope(), .stub()
src/oridecon/nosql/config.pyNoSQLConfig, MongoDBConfig, NamedNoSQLConfig
src/oridecon/nosql/di/provider.pyNoSQLProvider boot and registration
src/oridecon/nosql/backends/mongodb/backend.pyMongoDBDocumentStore implementation
src/oridecon/nosql/query/builder.pyDocumentQueryBuilder
src/oridecon/nosql/query/pipeline.pyAggregationPipeline
src/oridecon/nosql/repository/base.pyDocumentRepository base class
src/oridecon/nosql/migration/manager.pyMigrationManager