Watch keynotes and sessions from, our virtual developer conference.

How to Connect Flask-mongoengine to MongoDB Atlas

I’m very new to MongoDB. I am creating a Flask app with flask-mongoengine hopefully connected to a mongodb atlas cluster. I haven’t been able to connect (each time I try I get ServerSelectionTimeoutError).

This is in my

MONGODB_HOST = “mongodb+srv://:@/test?retryWrites=true&w=majority”

Thanks in advance!

Welcome to Community!

Are you able to connect with shell using your SRV connect string?
Don’t see userid/pwd placeholders in your string
Can you ping your cluster?

Connect string should look like below format

When trying to connect the shell, it didn’t connect:

exception: connect failed``` is whitelisted

I’ll try the shell method right now

Sorry, I removed the user id, password, and clustername for security purposes. What address should I try to ping? ?

Were you able to connect by shell?

ping your cluster something like below based on your cluster name

Hi mate,

Here an example of how to connect to Atlas using MongoDB client and Flask.

replace: “mongodbaddress” with mongodb+srv://:@/test?retryWrites=true&w=majority