UnhandledPromiseRejectionWarning: MongoError: not authorized on elm to execute comman

Error in starting node project

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

The reason is that you do not have permission to connect to the database

The reason is that the database mongo.conf There is an auth = true solution

1. Comment out auth = true

2. Enter adimn to set the user name and password, and use the user name and password to access the database

Switch use admin before creating user

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

Read More: