mongodbfluttermongo-dart

why it is not good to connect to MongoDB without an API?


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:

    mongodb+srv://username:<password>@clustername.eoxer.mongodb.net/<dbname>?retryWrites=true&w=majority