Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command insert requires authentication

I have tried this

mongoose.connect('mongodb://localhost/ninjago', { useNewUrlParser: true });  

to connect mongodb on nodejs and working fine.

But when i try to create data, it gives this error

"(node:18194) UnhandledPromiseRejectionWarning: MongoError: command insert requires authentication"

can anyone help me out? i am using ubuntu 18.04.

like image 761
Bipin Avatar asked Apr 01 '19 16:04

Bipin


2 Answers

Specify the username and password in your MongoDB URI. Something like:

mongoose.connect('mongodb://user:pass@localhost/ninjago', …

Reference:

  • Mongoose Connections Documentation
like image 64
Brad Avatar answered Nov 17 '22 04:11

Brad


Check if the database name exist and specify the port

like image 44
ofall Avatar answered Nov 17 '22 04:11

ofall