mongodb - 当 heroku 节点应用程序尝试使用和尚访问 mlab db 插件时的状态 503
问题描述
我正在尝试在 heroku 上部署我的 express-mongodb 应用程序。我已经尝试在本地访问 heroky mlab 插件,并且本地服务器工作正常。但是当我在 heroku 上启动同一台服务器时,由于缺少数据库,服务器似乎无法解决请求。我想知道是僧侣js还是其他问题。
<!-- language: lang-javascript-->
const express = require('express');
const bodyParser = require('body-parser');
const monk = require('monk');
const engines = require('consolidate');
const app = express();
const router = require('./routes/router');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(`${__dirname}/public`));
app.set('views', `${__dirname}/templates`);
app.engine('html', engines.mustache);
app.set('view engine', 'html');
const db = monk('mongodb://<xxxx>.mlab.com:15338/heroku_1xx37v0b');
db.then(() =>{
console.log("connection success");
}).catch((e)=>{
console.error("Error !",e);
});
app.use((req, res, next) => { req.db = db; next(); });
app.use('/', router);
app.listen(process.env.PORT || 3000);
// ask something to the db
const collection = db.get('docUtenti');
collection.findOne({type: "docTotUtenti" }).then((doc) => {console.log(doc);})
解决方案
推荐阅读
- java - Log4j 不显示进程 PID
- python - 在Python中,当我将二维数组的一行设置为np.nan时,为什么会得到-9223372036854775808?
- c# - C# Label List not being released from memory
- javascript - Cannot retrieve Title from Strapi
- cypress - Cypress and IdentityServer
- arrays - How to convert XML array text items into numbers in ColdFusion?
- flutter - How to set state of StateNotifierProvider
- bash - 如何让 bash 确定孩子是否存在段错误?
- jmeter - 如何使用 jmeter OS 进程采样器
- python - Windows kivy 应用程序使用 PyInstaller 成功构建,但不起作用