QweryBot
QweryBot

Reputation: 467

Difference between PyMongo and Flask-PyMongo libraries

I'm new to PyMongo and Flask, I have completed the tutorial for flask though and feel rather comfortable with it. I am now trying to implement a flask server with MongoDb and I'm not sure how to progress.

I see there are two libraries, PyMongo and Flask-PyMongo. It's isn't clear to me which I should use, or if I need to use both. How they interoperate and such...

First, i'm trying to connect to a mongodb, I have that running in the background and I can see connections whenever I start up my flask server, so that must be working. PyMongo offers methods to connect to specific database using db = client['test-database']. Flask-pymongo seems to just give a db connection from nowhere when using mongo = PyMongo(app) then mongo.db for access to the db.

Being new to mongo as well this is all confusing for me, I was hoping someone would be able to give me a clear answer to all my questions, searches around the web don't reveal many results for flask-pymongo library.

I did have a look at this question: What is the relationship between flask, mongokit, pymongo, flask-pymongo?, but it did not clear anything up for me.

Upvotes: 12

Views: 8860

Answers (1)

DobleL
DobleL

Reputation: 3928

The main difference is that flask-pymongo is a wrapper of pymongo ready to work on flask's application environment.

You can configure the database connection within flask application config object.

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

For example: pymongo have find() method, while flask-pymongo have an extension named find_or_404() which raise a not found exception if the item does not exist, and so on..

Upvotes: 9

Related Questions