我在连接 mongodb 和 heroku 时遇到问题。本地我连接没有问题尝试使用您在 heroku 中使用的数据库的 uri 没有问题,它也不起作用。这是我的连接存档const bodyParser = require('body-parser');const morgan = require('morgan');const express = require('express');const mongoose= require('mongoose');const app = express();const userRoutes = require('./routes/users');const reportRoutes = require('./routes/reports');//mongoose.connect('mongodb://localhost:27017/panic');mongoose.Promise = global.Promise;mongoose.connect('mongodb+srv://admin:<password>@panic-database-kpamh.mongodb.net/usuarios?retryWrites=true',{useCreateIndex: true,useNewUrlParser: true}).then(db => console.log("db is connect")).catch(err=> console.log(err));//SETTINGSapp.set('port',process.env.PORT || 3000);//middlewaresapp.use(morgan('dev'));app.use(bodyParser.json());//routes app.use('/users',userRoutes);app.use('/reports',reportRoutes);//START SERVERapp.listen(app.get('port'),()=>{ console.log('Server on port',app.get('port'));});
添加回答
举报
0/150
提交
取消