一起使用 MongoEngine 和 PyMongo

问题描述:

我想在我的下一个项目中使用 MongoEngine.现在我想知道我是否也可以在同一个项目中直接使用 PyMongo.只是因为我需要一些非常特别的东西,而 mongoengine 不直接支持.

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!?

这里是 MongoEngine 的作者 - MongoEngine 是建立在 pymongo 之上的,所以你当然可以进入 pymongo - 或者在你的代码中使用原始 pymongo!

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

有一些文档助手允许您访问 MongoEngine 中的原始 pymongo 方法,例如:

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