Lur1an/python-telegram-bot-template

Mongo relationships

Closed this issue · 2 comments

I was wondering how you'd make relationships (many to many, one to many, one to one..) using this template's database structure.

I'd open a discussion for this, normally, but I don't think you enabled them in this repo.

Thanks in advance for any reply.

Lur1an commented

MongoDB is not a relational database, thinking in relationships only will get you in trouble quickly.
You can create DBRef fields in MongoDB documents to track relationships between collections (even lists of em), if you cannot solve your problems through denormalization & embedding.
You can start reading here https://www.mongodb.com/docs/manual/core/data-modeling-introduction/

I do realize that Mongo is not a good DB for beginners, and despite being easier to setup, working with your data just becomes harder over time, thus overcomplicating this template.

I have good news for you as I made a lot of telegram bots with SQLAlchemy + SQLite + Alembic stack recently, I will clean up some code and replace the persistence layer with that when I find the time for it. This repo is work in 🚧progress🚧, but expect an update soon, I will reference this issue in a small PR 😉

Thats great news! I made myself a little template using sqlalchemy+aiosqlite+alembic inspiring myself to yours, and i thought it could've been a good idea migrate to mongo, but I had those relationships problems and i just tought to go back to sqlalchemy...
If you, for any reason, need a little bit of help on this, please feel free to ask :)