Skip to content

# Best Practices

1. Always use ModelRegistry.register() before initializing the database connection
2. Use lifespan context manager for proper connection lifecycle
3. Inherit from BaseDocument for all models to get auto-timestamps
4. Create custom repository classes for business logic instead of mixing it with models
5. Use transactions for operations that modify multiple documents
6. Add indexes during model registration for frequently queried fields
7. Implement pagination for list endpoints to avoid performance issues
8. Use type hints for better IDE support and type checking