在 heroku 上部署后无法解决 mongodb atlas 出现的错误?

Couldn't resolve the error coming for mongodb atlas after deploying it on heroku?

应用程序在本地运行良好,但当我将其部署到 heroku 时,它在 heroku 日志中显示错误。 mongoDb 数据库中也没有添加数据。实际上在应用程序中我使用了 google-oauth login 所以在本地它工作得很好但在 heroku 中却不行。我也在 mongodb atlas 上将我的 ip 列入白名单,但仍然无法弄清楚为什么会出现此错误。

谁能帮帮我.....

这是我的 prod.js 文件

module.exports = {
    googleClientID: process.env.GOOGLE_CLIENT_ID,
    googleClientSecret: process.env.GOOGLE_CLIENT_SECRET,
    mongoURI: process.env.MONGO_URI,
    cookieKey: process.env.COOKIE_KEY
}

这是我的 keys.js 文件

// Keys.js - figure out what credentials should return

if (process.env.NODE_ENV === "production") {
    // So we are in prodution - return the prod set of keys
    module.exports = require('./prod');
} else {
    // We are developement - return the dev keys
    module.exports = require('./dev');
}

这是我的 index.js 文件

const express = require('express');
const mongoose = require('mongoose');
const passport = require('passport');
const cookieSession = require('cookie-session');
const keys = require('./config/keys');
require('./models/User');
require('./services/passport');

const app = express();

//Middleware
app.use(
    cookieSession({
        maxAge: 30 * 24 * 60 * 60 * 1000,
        keys: [keys.cookieKey]
    })
);
app.use(passport.initialize());
app.use(passport.session());

// mongoDb Connection
mongoose.connect(keys.mongoURI, {
        useNewUrlParser: true
    }).then(() => console.log('MongoDb Connect successfully'))
    .catch(err => console.log(err));


// actual routes
require('./routes/authRoutes')(app);


const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server is running in ${PORT}`));

实际上我首先得到两个不同的错误是这个

2019-09-02T06:28:59.760121+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2019-09-02T06:28:59.760149+00:00 app[web.1]: designed for a production environment, as it will leak
2019-09-02T06:28:59.760151+00:00 app[web.1]: memory, and will not scale past a single process.
2019-09-02T06:28:59.763577+00:00 app[web.1]: 
2019-09-02T06:28:59.763581+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:519
2019-09-02T06:28:59.763583+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2019-09-02T06:28:59.763585+00:00 app[web.1]: ^
2019-09-02T06:28:59.763838+00:00 app[web.1]: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2019-09-02T06:28:59.763842+00:00 app[web.1]: at new MongooseError (/app/node_modules/mongoose/lib/error/mongooseError.js:10:11)
2019-09-02T06:28:59.763844+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:519:11)
2019-09-02T06:28:59.763846+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:321:15)
2019-09-02T06:28:59.763848+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:24:10)
2019-09-02T06:28:59.763850+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:701:30)
2019-09-02T06:28:59.763852+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
2019-09-02T06:28:59.763854+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:600:32)

第二个是这个

2019-09-02T08:49:22.115492+00:00 app[web.1]: { MongoNetworkError: failed to connect to server [productionproj-shard-00-00-qfouv.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to productionproj-shard-00-00-qfouv.mongodb.net:27017 closed]

等等……同上

这是我的 mongodb 产品 url 我已经添加到 heroku 配置变量中

mongodb+srv://nansProdDeploy:nansProdDeploy@productionproj-qfouv.mongodb.net/test?retryWrites=true&w=majority

一切都是为了将​​正确的 IP 地址列入白名单。当我们将我们的应用程序放在 heroku 上时,我们必须通过单击 [ 允许从任何地方访问 ] 按钮将 ip 列入白名单,然后单击确定你的 ip 将是 0.0.0.0/0 这个 ip 将允许访问您部署的 heroku 应用程序。当您在本地使用您的应用程序时,您必须选择 [ 添加当前 IP 地址] 以在本地访问您的应用程序