Skip to content

Working with beanie/motor transactions/sessions #692

Discussion options

You must be logged in to vote

Found a way to make it work. Here is a code example

import logging
from contextlib import asynccontextmanager
from datetime import datetime
from functools import wraps
from typing import Annotated, Sequence, Type

import motor.motor_asyncio
import uvicorn
from beanie import Document, init_beanie
from fastapi import Depends, FastAPI
from pydantic import BaseModel, Field


class ItemModel(BaseModel):
    name: str
    description: str
    date: datetime = Field(default_factory=lambda: datetime.now())


class Item(Document, ItemModel):

    class Settings:
        collection = "items"


client = motor.motor_asyncio.AsyncIOMotorClient('mongodb://localhost:27017')


async def get_client():
   …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yousafsabir
Comment options

Answer selected by leonballoniMakes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants