Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (50.2k points)
How can I connect a Flask application with the MongoDB database?

1 Answer

0 votes
by (107k points)
edited by

You can use pymongo to connect to the MongoDB database. You have to first import the MongoClient and then you have to create a connection with the database, refer to the following code:

from pymongo import MongoClient

client = MongoClient()

Then fetch your database instance and collection with the help of the following code:

Learn about full stack web development by signing up for this professional Full Stack Training offered by Intellipaat..

db = client.my_database

collection = db.my_collection

Related questions

0 votes
1 answer
0 votes
2 answers
asked Oct 18, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...