【发布时间】:2020-08-09 11:10:42
【问题描述】:
我可以在本地运行一切正常,并且应用程序显示在 Heroku 上(全部使用本地 mongoose 数据库),但如果我切换到 MongoDB 数据库,使用 MongoDB 提供的代码,本地 (goorm) 和当我做任何需要解决数据库问题的事情时,Heroku 网站都会失败。
Heroku 日志中出现的第一个错误是:
2020-08-08T15:57:45.898855+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-08T15:57:46.903138+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=lit-forest-68974.heroku app.com request_id=a99ca76f-f8a8-4790-bf83-d42c24cc17d7 fwd="77.11.27.47" dyno= connect= service= status=503 bytes= protocol=https
2020-08-08T15:57:47.298492+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=lit-forest-68974.herokuapp.com request_id=cf828829-07cf-4c23-861f-3a123039a66f fwd="77.11.27.47" dyno= connect= service= status=503 bytes= protoco
l=https
我在想(希望)问题在于我如何在 app.js 文件中引用数据库。我正在使用:
const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://NeilGreer:Ng232117@clearport1.sxp3s.mongodb.net/clearport11?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true , useUnifiedTopology: true});
client.connect(err => {
const collection = client.db("test").collection("devices");
// perform actions on the collection object
client.close();
});
这是直接从MongoDB复制的代码。'
有没有人遇到过类似的问题?
【问题讨论】:
-
如果您的
uri变量包含您的实际用户/密码,请考虑编辑和删除它们。