无法将Mongo DB连接到Heroku

时间:2020-02-19 19:19:02

标签: node.js mongodb express

我正在跟踪Web开发的训练营,我正在删除数据库部分。问题是与db的连接在本地环境下工作正常(使用mongodb字符串),但与heroku无关。您能帮我吗?我已经尝试了许多更改端口和其他解决方案的方法,但是没有任何效果。

        app                 = express (),
        bodyParser          = require('body-parser'),
        mongoose            = require("mongoose"),
        passport            = require("passport"),
        LocalStrategy       = require("passport-local"),
        methodOverride      = require("method-override"),
        flash               = require("connect-flash")   
//models
var     Campground          = require("./models/campground"),
        Comment             = require("./models/comment"),
        User                = require("./models/user")
//routes
var     commentRoutes       = require("./routes/comments"),
        campgroundRoutes    = require("./routes/campgrounds"),
        indexRoutes         = require("./routes/index")



// mongoose.connect("mongodb://localhost:27017/yelpjul", {useNewUrlParser: true, useUnifiedTopology: true,useFindAndModify: false});
mongoose.connect("mongodb+srv://GerindT:password@yelp-e3rz8.mongodb.net/test?retryWrites=true&w=majority");


app.listen(process.env.PORT,function(){
    console.log("Started");
});
// process.env.PORT```

0 个答案:

没有答案