为什么在没有 API 的情况下连接到 MongoDB 不好?

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

我想在我的 flutter 项目中使用 mongo atlas,目前,我正在使用 mongo_dart 包,我可以直接从我的应用程序添加文档。

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');

最近看到有人说要创建API,这样用MongoDB不好。你能解释一下为什么我需要创建一个 API 吗?

所以根据你在这里所说的,即 why it is not good to connect to MongoDB without an API?

所以我相信我会得到纠正:

  • 所以 mongoDB atlas 在连接到它之前你必须验证自己

  • Mongo 将为您提供如下所示的连接字符串:

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

  • 因此,如果连接是经过身份验证的连接,mongoDB 支持他们为他们的驱动程序指定的语言

    ,那么会更安全
  • 因此,如果您查看此处给出的解决方案,就会出现颤动: 似乎它不是经过身份验证的连接,因此安全性较低