Thomas Kremmel
Thomas Kremmel

Reputation: 14783

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

Upvotes: 26

Views: 10214

Answers (1)

Ross
Ross

Reputation: 18101

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

Upvotes: 55

Related Questions