MongoEngine/mongoengine

Can I only use the classes, and use the Motor itself for any kind of database operations?

caner-cetin opened this issue · 1 comments

Hello. Just for the type of safety, i will migrate my codebase from a dictionary based approach

post  = mongodb.find(...)
print(post["title"], post["author"], post["tags"])

to

class Post(Document):
    title = StringField(max_length=120, required=True)
    author = ReferenceField(User)
    tags = ListField(StringField(max_length=30))

post = mongodb.find(...)
print(post.title, post.author, post.tags)

My question is, can I only use the class part of the library, and use it with Motor? I dont want to use Motor from the ODM, I want to use Motor itself directly, but still, I need type safety.

thanks for this awesome project, and thanks for any replies!

MongoEngine is deeply integrated with pymongo and MongoEngine's Document classes are tighly coupled with the pymongo connection so I think you'll have a hard time to achieve what you want.

You probably better use simple pydantic classes and then the repository pattern