Error [MongooseError]: The uri
parameter to openUri()
must be a string, got "undefined". Make sure the first parameter to mongoose.connect()
or mongoose.createConnection()
is aongoose\\lib\\error\\mongooseError.js:10:11) string.
const express = require("express"); const expressLayouts = require("express-ejs-layouts"); const mongoose = require("mongoose"); const MongoClient = require('mongodb').MongoClient; const app = express(); // DB Config const db = require('./config/keys').MongoURI; //Connect to Mongo mongoose.connect(db, { useNewUrlParser: true, useCreateIndex: true ,useUnifiedTopology: true}) .then(() => console.log("MongoDB connected ....")) .catch(err =>console.log(err));
const mongoose = require("mongoose");
module.exports ={
mognoURI:"mongodb+srv://pratham:<pratham>@psm-94d4p.mongodb.net/test?retryWrites=true&w=majority"
};
You need to create a config folder and inside the config folder, you need to add keys.js file
which looks like this
module.exports = {
MongoURI: 'here goes your connection string which you will get from MongoDB atlas'
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.