Skip to content

Commit 059faec

Browse files
committed
use flask_pymongo.PyMongo
1 parent f0c6ab8 commit 059faec

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

source/integrations/flask-celery-integration.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ Define the necessary configurations by adding the following code to your
161161
MAIL_PASSWORD = '<app password>'
162162
MAIL_DEFAULT_SENDER = '<email address>'
163163
MONGO_URI = '<mongodb connection string>'
164+
DATABASE_NAME = "newsletter"
164165
ALLOWED_IPS = ['127.0.0.1']
165166
MAIL_SERVER = 'smtp.gmail.com'
166167
MAIL_PORT = 587
@@ -208,7 +209,7 @@ Initialize Flask, MongoDB, and Celery by adding the following code to your
208209

209210
from flask import Flask
210211
from flask_mail import Mail
211-
from pymongo import MongoClient
212+
from flask_pymongo import PyMongo
212213
from celery import Celery
213214

214215
# Create a Flask application
@@ -219,8 +220,8 @@ Initialize Flask, MongoDB, and Celery by adding the following code to your
219220
mail = Mail(app)
220221

221222
# Connect to MongoDB
222-
client = MongoClient(app.config['MONGO_URI'])
223-
db = client.get_database(name="newsletter")
223+
client = PyMongo(app).cx
224+
db = client[app.config['DATABASE_NAME']]
224225

225226
# Create a Celery instance
226227
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])

0 commit comments

Comments
 (0)