如何通过httpsAPI访问MongoDB图集?

How to access MongoDB atlas through https API?

自从我迁移到 Mongodb Atlas 后,我遇到了 cors 错误

我在 mongodb 仪表板上找到的唯一 URL 是 mongodb+srv://<username>:<password>@cluster0.cnh0m.mongodb.net/myFirstDatabase

这是我的代码:


getClap = async () => {
    try {
        const res = await axios.get(`mongodb+srv://...`)
        console.log(res.data);
    } catch (err) console.error(err);
};

有什么方法可以像以前使用 mlab 一样将 mongodb 直接连接到 axios 吗?使用 HTTPS 地址 ?

我在 mlab 文档中找到了答案。

Q. Does Atlas have a Data API?

If you are using the mLab Data API note that MongoDB Atlas does not have a data API. However, we have open-sourced the mLab Data API and made it easy for you to self-host the mLab Data API on Heroku.

Once you have re-configured your application to use your self-hosted mLab Data API, you’ll be able to migrate your mLab-hosted deployments to MongoDB Atlas.

source link