Issue
I want to use mongo atlas in my flutter project and currently, I am using the mongo_dart package and I am able to add documents directly from my app.
var db = await Db.create("mongodb+srv://<username>:<password>@cluster0.cwdcc.mongodb.net/<database>?retryWrites=true&w=majority");
await db.open();
var coll = db.collection('Users');
Recently I saw someone saying that I need to create API and it is not good to use MongoDB like this. Can you explain Why is that I need to create an API?
Solution
So based what you saying here i.e why it is not good to connect to MongoDB without an API?
So I am to believe I stand to be corrected:
-
So mongoDB atlas before even connecting to it you have to authenticate yourself
-
Mongo will give you a connection string like this below:
mongodb+srv://username:<password>@clustername.eoxer.mongodb.net/<dbname>?retryWrites=true&w=majority
-
So it is much safer when then connection is an authenticated connection which mongoDB supports for the languages that they specified for their driver that they have
-
So with flutter if you look at this solution given here:How to connect flutter with MongoDB it seems like it is not an authenticated connection which makes it less secure
Answered By – Ntshembo Hlongwane
Answer Checked By – Katrina (FlutterFixes Volunteer)