Use MongoEngine and PyMongo together

只谈情不闲聊 提交于 2020-07-04 06:22:17

问题


I want to use MongoEngine for my next project. Now I'm wondering whether I could also use PyMongo directly in the same project. Just for the case that I need something very special that is not supported directly via mongoengine.

Are there any doubts that this would work, or that I should not do that!?


回答1:


Author of MongoEngine here - MongoEngine is built upon pymongo so of course you can drop into pymongo - or use raw pymongo in your code!

There are some document helpers that allow you to access raw pymongo methods in MongoEngine eg:

class Person(Document):
    name = StringField()

# Access the pymongo collection for the Person document
collection = Person._get_collection()
collection.find_one()  # Use raw pymongo to query data


来源:https://stackoverflow.com/questions/12068558/use-mongoengine-and-pymongo-together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!