Database user administration

You can create database users to suit the purposes of administration and also to control access from applications that are using MongoDB programming language drivers.  Here is a list of the more important mongo shell database commands that are used to manage users:

  • db.getUser("<name>"): Retrieves information on user <name>
  • db.createUser(<user document>): Creates a user
  • db.changeUserPassword("<name>", "<new password>"): Changes password for existing user <name>
  • db.updateUser("<name>",<update document>): Updates user <name> with the information in <update document>
  • db.dropUser("<name>"): Removes user <name> from the database

In the following example, we are creating a user called sweetsBasic who has readWrite ...

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.