問題描述
一起使用 MongoEngine 和 PyMongo (Use MongoEngine and PyMongo together)
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:
<pre class="lang‑py prettyprint‑override">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
</code></pre>
(by Thomas Kremmel、Ross)
參考文件