Initializing security

Setting up initial security in MongoDB is actually an extremely simple operation. Here are the steps that need to be performed:

  • Start the mongod instance with no security.
  • Access the database using the mongo shell or an admin tool such as MongoDB Compass.
  • Create an admin user.  In the following example, the admin user is superMan and has the role userAdminAnyDatabase, which grants the rights to add, edit, or remove database users for any database:

  • Restart mongod with security. You can either use the mongod command switch --auth, or add the following to the MongoDB config file:
      security:           authorization: enabled

Once ...

Get MongoDB 4 Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.