beanie vs pymongo
from typing import Optional, List
import motor
from beanie import Document, init_beanie
from pydantic import BaseModel
class Tag(BaseModel):
name: str
color: str
class Note(Document):
title: str
text: Optional[str]
tag_list: List[Tag] = []
async def main():
# Crete Motor client
client = motor.motor_asyncio.AsyncIOMotorClient(
"mongodb://user:pass@host:27017"
)
# Init beanie with the Note document class
await init_beanie(database=client.db_name, document_models=[Note])
# Get all the notes
all_notes = await Note.find_all().to_list()