提问人:sahil 提问时间:11/2/2023 最后编辑:parwatcodessahil 更新时间:11/2/2023 访问量:38
MongooseError:“openUri()”的“uri”参数必须是一个字符串,得到“undefined”。确保 'mongoose.connect() 的第一个参数是字符串
MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect() is a string
问:
const mongoose = require("mongoose");
const connectDatabase = async () => {
await mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true });
console.log("MongoDB Connection Successfully");
};
module.exports = connectDatabase;
我的文件config.env
MONGO_URI = mongodb+srv://username:<password>@cluster0.aq9vco8.mongodb.net/?retryWrites=true&w=majority
答: 暂无答案
评论
connectDatabase
console.log('uri=', process.env.MONGO_URI)
dotenv
.env