MongoDB modelling for managing company workspaces

Viewed 61

while I've some experience with SQL dbs, I'm pretty new to MongoDB and NOSQL dbs. I'm currently implementing an API with Fast-API and MongoDB. I've the following requirements:

  • I've to handle the concept of workspace, which basically is a dedicated space for a company.
  • Every workspace can have members with different roles.
  • Inside a workspace I can create Teams. A team can live without members or have members assigned to it and it belongs only to one workspace (so inside two different workspaces we can have teams with the same name).

This is my current model. I'm using Odmantic ODM (but I guess this is not relevant).

from typing import Optional, List
from odmantic import Model, Field, ObjectId, EmbeddedModel
from datetime import datetime


class Team(Model):
    name: str
    workspace: ObjectId


class WorkspaceMember(EmbeddedModel):
    email: str
    role: str
    team: Optional[Team] = None 


class Workspace(Model):
    name: str
    members: Optional[List[WorkspaceMember]] = None
    teams: Optional[Team] = None
    created_at: datetime = Field(default=datetime.utcnow())

    class Config:
        collection = "workspaces"

Do you think I'm on the right path? I'm not sure if this is the most correct way of doing what I want to do. Feedback would be really appreciated.

0 Answers
Related