S
S
SalimILE2015-12-04 16:52:45
MongoDB
SalimILE, 2015-12-04 16:52:45

How to access mongodb database with password and login?

Hello, tell me how to access the database in nodejs for example

mongoose.connect('mongodb://<username><password>localhost/test');

i.e. where to create a user?
and how to make it possible to connect to the database through authorization?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel, 2015-12-04
@SalimILE

Oddly enough, in the mongi documentation, all this is described.
create user:

mongo
>>use  "db name"
>>db.createUser(
  {
    user: "user_name",
    pwd: "user_passwd",
    roles: [{role: "readWrite"}]
  }
)

to require authorization, you should specify auth=true in the mongo config

B
BEKa T, 2019-08-13
@Bread09

Or you can not download Mongo, and use the cloud Mongo

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question