Search code examples
mongodbdjango-rest-frameworkpymongomongoenginedjongo

Mongoengine and Pymongo?


Can I use mongoengine or djongo for ODM and pymongo for interaction with the db?

I've read these two about something related to my question:

Insert data by pymongo using mongoengine ORM in pyramid

Use MongoEngine and PyMongo together

But, I couldn't find what I'm looking for (I guess). So here's what I'm trying to find:

¿Does this practice affect the performance of my application? ¿How well recommended is it?

So, if it is recommended, and everything is right, ¿Do I need to put an extra layer of security or something?, because, I want to build an API using the serializations for models that django-rest-framework-mongoengine offers, and then do what I have to do in the view of the API endpoint.

It could be djongo or something like it, what I want is just an ODM for serializing, define a structure for the API and so on, use pymongo for queries, cause according to what I've been reading, mongoengine could make slower the interaction with the db


Solution

  • The term "ORM" does not apply to MongoDB since MongoDB is non-relational. The proper term is "ODM" - object-document mapper.

    Generally, a MongoDB ODM is built on top of a MongoDB driver. The functionalities of the ODM and the driver are complementary - the driver provides low-level database access and the ODM provides high-level features like schema, associations, callbacks.

    If you want to use the high-level features, it makes sense to use an ODM. If you don't need any of those features and just want to perform basic CRUD operations, using a driver directly is more efficient. Some applications use both of these strategies depending on the operation that needs to be performed.