Reputation: 1339
Can't find answer anywhere. This is the problem:
I set it up on digitalocean my NodeJS project with MongoDB. I've installed NodeJS and MongoDB, and also cloned my project. At first I run my project on port 8888 and it worked fine with mongodb. Then I added admin
user to the admin
table and whenever I again run my nodejs project I get this error
UnhandledPromiseRejectionWarning: MongoError: not authorized on test to execute command
How to authorize then ? Should I somehow authorize before running my app ?
The user that I've created:
db.createUser(
{
user: "******",
pwd: "****",
roles: [ { role: "root", db: "admin" } ]
}
)
Upvotes: 1
Views: 256
Reputation: 1681
You need to change mongodb connection string with user authentication to avoid this issue. if your created use "admin_user" and password "test1234" and mongodb server "127.0.0.1:27017" then connection string looks like below,
"MONGODB_URL": "mongodb://admin_user:[email protected]:27017/YourDBName",
Upvotes: 3