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 uses PyMongo behind the scenes to manage the connections to the database. It is meant to be an easy entryway for developers used to working with SQLAlchemy or other similar ORMs. This can reduce the learning curve when software engineers are first introduced to MongoDB and its document model.
PyMongo is the low-level driver wrapping the MongoDB API into Python and delivering JSON in and out. MongoEngine or other layers like MongoKit map your MongoDB-based data to objects similar to native Python database drivers + SQLAlchemy as ORM.
MongoEngine is a Document-Object Mapper (think ORM, but for document databases) for working with MongoDB from Python. It uses a simple declarative API, similar to the Django ORM. Documentation available at docs.mongoengine.org - there is currently a tutorial, a user guide and API reference.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With