Connecting to a MongoDB in Flask Using Flask-PyMongo

preview_player
Показать описание
This video demonstrates how to connect to a MongoDB using Flask, create a collection, and add data to it.

WORK WITH ME👇🏼

✅ Need help with your project? Schedule a call with me at:

💻 Code written in video
Рекомендации по теме
Комментарии
Автор

Thanks for the video!! is not easy to find a professional and simple way to setup flask and pymongo and it really helped me

joserodriguezgomez
Автор

Anthony, I love your tutorials, also the flask one on Udemy. Some of the material there looks a bit dated, could you please consider having a Flask-Mongo-Heroku unit added with the newer technology available? It would be great to see how you do this, including a register/login/logout part and interacting with the database in some way. Thanks!

GPBrachetta
Автор

Hi! Thanks for the informative video. I was wondering if you had planned on making an extension to include the rest of CRUD?

willcshapiro
Автор

I noticed pipenv takes much longer than bare pip to install basic requirements. I know it makes a lot of other stuff as well, but still, the wait can get pretty annoying over time.

ChumX
Автор

This is the most difficult way I've ever seen pymongo set up.

RizzoDaManiac
Автор

I am running these file in atom, running successfully but unable to get localhost url

footballforfun
Автор

I tried connecting mongoalchemy with atlas but it doesn't accept the uri from atlas. Is there a solution for this?

nwtou
Автор

I have no idea what you're talking about.:D

didadadadadi
Автор

i have import flask but when i run it.The system have bug :{
"resource": "/c:/Users/nhatn/OneDrive/Desktop/fask-pymongo/pymongtool/__init_.py",
"owner": "_generated_diagnostic_collection_name_#0",
"code": "unresolved-import",
"severity": 4,
"message": "unresolved import 'flask'",
"source": "Python",
"startLineNumber": 2,
"startColumn": 6,
"endLineNumber": 2,
"endColumn": 11
}

namnguyennhat
Автор

You made your life easier by modularizing the code but it's confusing for a tutorial.

Beyondhumanlimits
Автор

I have the same problem as "Danny corgan", that is:
I created a script to populate my database. It reads informations from a .txt file and appends it all to a list which is used with insert_many method from pymongo. However, I'm not quite sure I can reference my database object in the script. I definitely can hardcoding the information:
from flask_pymongo import PyMongo
from pymongo import MongoClient
...
# Connect to database
client = MongoClient('...')
db = client.homophones
homophonesCollection = db.homophones

This way I can use my Collection as I wanted. However, this is far from ideal and this way my URI is exposed.
If I use this instead:
from .extensions import mongo

I get this right away:
File "populate_db.py", line 12, in <module>
from .extensions import mongo
ModuleNotFoundError: No module named '__main__.extensions'; '__main__' is not a package

Removing the dot before "extensions" and copying main.py's instantiation of Collection:
from extensions import mongo
...
user_collection = mongo.db.users

This happens:
File "populate_db.py", line 18, in populate_db
user_collection = mongo.db.users
AttributeError: 'NoneType' object has no attribute 'users'

Any help here? So far I've been able to create a web application thanks in great part to you put that heavily modular setup seems to have confused a lot of folks here. I searched quite a bit and couldn't figure out what to do. Can you elaborate more how can I connect to my database/get database object in a different script inside my flask application (like the populate_db.py I mentioned?)

LeEnnyFace
Автор

I'm getting 'MONGO_URI' is not defined as an error, any solutions?

XEPICSAMX
Автор

problem I get a message No module named '__main__.extensions' ? any help welcomed

dannycorganrg
Автор

Hello, can we not download MongoDB and use it instead of using the cloud database.

manabsaha