Difference between PyMongo and Flask-PyMongo Libraries

I am new to PyMongo and Flask, but I have finished the flask tutorial and feel pretty comfortable with it. Now I am trying to implement a flash server with MongoDb, and I am not sure how to proceed.

I see that there are two libraries PyMongo and Flask-PyMongo. It is not clear to me what I should use, or I need to use both. How do they interact and such ...

Firstly, I try to connect to mongodb, it works for me in the background, and I see connections when I start my flask server, so it should work. PyMongo offers methods for connecting to a specific database using db = client['test-database'] . It seems that Flask-pymongo just gives a db connection from nowhere when using mongo = PyMongo(app) , then mongo.db to access the db.

Being a newcomer to mongo, this all confuses me, I was hoping that someone could give me a clear answer to all my questions, searches on the Internet do not show many results in the library of flux pimongo.

I looked at this question: What is the relationship between a flask, a mongokit, a pimongo, a flask pimongo? but she understood nothing for me.

+5
source share
1 answer

The main difference is that flux pimongo is a pimongo wrapper ready to work in flask environments, as IanAuld already said.

You can configure the database connection in the configuration object of the flag application.

Flask-pymongo also implements helper methods on top of pymongo ..

In the example: pymongo has the find () method, while the flux-pymongo has an extension called find_or_404 (), which raises an unspecified exception if the item does not exist, etc.

+1
source

All Articles