UnhandledPromiseRejectionWarning: MongoError: not authorized on elm to execute comman

启动node项目报错 

UnhandledPromiseRejectionWarning: MongoError: not authorized on elm to execute command { insert: "hongbaos", ordered: false, $db: "elm" }

原因是没有连接数据库权限

原因是数据库 的mongo.conf 里面有一个 auth=true 两种解决办法

1、把auth=true注释掉

2、进入到adimn中设置用户名密码,利用用户名密码进行访问数据库

在createUser之前先use admin切换一下

db.createUser(
	{
		user:"root",
		pwd:"123456",
		roles:[{role:"root",db:"admin"}]
	}
);

猜你喜欢

转载自blog.csdn.net/wangjie33589/article/details/114982667