在cPanel中连接云mongoDb



Hy伙计们,可以在cPanel中连接云mongodb。现在我有服务器错误502,因为我了解它的mongoDb错误。我不太擅长这方面的工作,部署项目。

我的代码:

const PORT = --PORT;
const hostname = --hostname;
const DB_URL = 'mongodb+srv://user:password@cluster0.4ie8h.mongodb.net/bootcamp?retryWrites=true&w=majority';

async function start(){
try{
mongoose.connect(DB_URL, {
useUnifiedTopology: true,
useNewUrlParser: true,
autoIndex: true,
})
app.listen(PORT, hostname, () => { console.log('Server started on port ' + PORT)});
}catch(e){
console.log(e);
}
}

start((;

您的代码似乎是绝对正确的。请记住;502";通常是";坏网关";错误,这意味着很可能您的web服务没有正确地将请求转发到应用程序的正确端口。确保在.htaccess文件中有正确的重写规则。你的网络托管提供商应该能够提供帮助。

最新更新