【发布时间】:2020-04-18 08:26:34
【问题描述】:
我在连接本地 mongoDB 时遇到问题。
Mongo 连接字符串:
const options = {
'useMongoClient': true,
};
mongoose.connect("mongodb://username:password@localhost:27017/DB?authSource=admin", options);
mongoose.connection.on('error', error => {
console.log(chalk.red('Database error'));
});
mongoose.connection.on('connected', () => {
console.log(chalk.green('Database connected');
});
错误
MongoDB 版本:
- MongoDB shell 版本 v3.4.9
- 连接到:mongodb://127.0.0.1:27017
- MongoDB 服务器版本:3.4.9
【问题讨论】:
-
用户名或密码可能有错误
-
@kedarsedai 感谢您的评论,但是在 mongo shell 上使用相同的用户名和密码。
-
那么你是在尝试连接
MongoDB Atlas吗?