node.js mongoError not authorized on admin to execute command

The npm module connect-mongo can't handle mongodb+srv:// connection strings. You'll have to use the older connection string types that start with mongodb://.

If you are using MongoDB Atlas I recommend to go to connect on the cluster view, then connect your application and then select Node.js version 2.2.12, not 3.0.

You probably also have to change the /test or /admin in your connection string to /TheNameOfYourDatabase with your database name there. (See radihuq's answer below)


@ConstJS answer worked for me. Expanding on it a little bit -

If you're using Postman and your error looks like this:

"errmsg": "not authorized on admin to execute command { insert: [..] }, $db: \"admin\" }"

Note this specific part:

$db: \"admin\"

You'll want to change that to your DB name so go to your URI and find

mongodb.net:27017/admin

and change admin to your database name