Integrating MongoDB with Flask

3 min readJul 7, 2021


What Is MongoDB?

MongoDB is an open-source document database built on a horizontal scale-out architecture. Founded in 2007, MongoDB has a worldwide following in the developer community.

Instead of storing data in tables of rows or columns like SQL databases, each row in a MongoDB database is a document described in JSON, a formatting language.

What is Flask?

Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions. However, Flask supports extensions that can add application features as if they were implemented in Flask itself. Extensions exist for object-relational mappers, form validation, upload handling, various open authentication technologies, and several common framework-related tools.

Why are ORMs useful?

ORMs provide a high-level abstraction upon a relational database that allows a developer to write Python code instead of SQL to create, read, update and delete data and schemas in their database. Developers can use the programming language they are comfortable with to work with a database instead of writing SQL statements or stored procedures.

My Project

Step-1: Install Prerequisite and Create a

>>First, we will install pymongo in order to integrate python with MongoDB.
#pip install pymogo
#pip install flask

>>This is the flask code for creating a flask app that will create an interface between Python and MongoDB.
>>This code can simply enter the database for students in school and can be used to view the data.

Step-2: This is a basic HTML form code to input details.

Step-3: Now we will start the flask app from our command prompt

Step-4: Now we will open the site in our browser and add the fields.

Step-6: Now, we can manually check by opening MongoDB in the command prompt. We can see that our created databases “db_shiv”, and collection name “students”.

Step-7: Now we would click the View_Collections to see the collection.

This is the Github link for the code above!!




Student from 2nd Year, A proud ARTH learner, love new technologies, Curious about many thing, likes to explore places, love eating pizza and much more.