0

I'm trying to follow the Flask-User documentation with MongoDB.

However, when I try to connect to my MongoDB Atlas, it's always writing to a "test" database, instead of the one I specify.

I have identified that it is because of the Flask-MongoEngine that is being used, as it mentions that

By default, Flask-MongoEngine assumes that the mongod instance is running on localhost on port 27017, and you wish to connect to the database named test.

However, even after inputting my URI details, I still keep writing to the test database.

Uri style connections are also supported, just supply the uri as the hostin the ‘MONGODB_SETTINGS’ dictionary with app.config. Note that database name from uri has priority over name.

app.config['MONGODB_SETTINGS'] = { 'db': 'project1', 'host': 'mongodb://localhost/database_name' } 
My code

My configuration settings (albeit in another syntax) are as below

app.config['MONGODB_DB'] = '<redcated-database-name>'
app.config['MONGODB_HOST'] = 'mongodb+srv://<redcated-user>:<redcated-pw>@gapcluster-np4bu.mongodb.net/test?retryWrites=true&w=majority'
app.config['MONGODB_PORT'] = 27017
app.config["MONGODB_CONNECTION"] = False

Has anyone successfully used Flask-User with MongoDB Atlas before?

  • 1
    Your MONGODB_HOST specifies the `test` database. See `/test?retryWrites=true&w=majority`. The `test` string there is your database name. – Joe Drumgoole May 25 '20 at 09:26
  • 1
    Thank you, this solved my query. I find it strange for the prompter that they gave below, it wasn't brought up that I would have to replace with the name of the database you want to write to. https://i.imgur.com/v0XOY6g.png Please submit it as an answer, and I'll be able to mark it as the solution! – lagrangian_headache May 26 '20 at 06:57

0 Answers0