John doe
John doe

Reputation: 3870

How to protect my mongodb database to be accessed without password?

I am discovering MongoDb and I realize that I can access my database from anywhere using mongodb compass just by entering my database URI and click connect.

So basically, If someone has the URI of my database, he can access it and do whatever he wants ?

How to avoid this by for example, password protect it ?

Upvotes: 0

Views: 473

Answers (2)

Wernfried Domscheit
Wernfried Domscheit

Reputation: 59456

Yes, by default MongoDB does not use authorization. Enable it in the configuration file:

security:
   authorization: enabled

see Configuration File Options security.authorization

Upvotes: 1

Gibbs
Gibbs

Reputation: 22956

  1. Add a user with required permissions/roles for the database.
  2. Enable access control and restart the server with auth option

Then only authenticated user can access the database

documentation

Upvotes: 1

Related Questions