如何允许任何机器通过我的网站访问mongodb地图集

我已经通过Zeit部署了我的练习应用程序。我的应用程序只能通过我的机器访问MongoDB地图集上的集群。通过手机或其他设备加载应用程序时,该应用程序似乎未连接到MongoDB。我如何做才能使其他计算机至少能够显示数据库中的数据?

我设置了一个白名单条目,以允许从任何IP访问。

    const uri = 'mongodb+srv://mytest:mypassword@cluster0-mqtm7.gcp.mongodb.net/test?retryWrites=true&w=majority'

     mongoose.connect(uri,{useUnifiedTopology: true,useNewUrlParser: true,useCreateIndex: true});

     const connection = mongoose.connection;
     connection.once('open',() => {
        console.log("MongoDB database connection established 
     successfully");
}).catch(error => {
    console.log(error);
})

当我在笔记本电脑上输入URL时,会显示数据库中的数据,但是当我尝试使用其他设备时,数据库似乎无法连接。

dcx6327 回答:如何允许任何机器通过我的网站访问mongodb地图集

将您的本地主机更改为新生成的url表单托管

例如:

localhost:5000/user/add 

my-app-3736.herokuapp.com/user/add
本文链接:https://www.f2er.com/3141158.html

大家都在问