Create and Remove MongoDB user to database

Create an user by first clicking on the terminal button were it says “MONGOSH” in the bottom left corner of the MongoDB compass program. Then write use <yourdbname> to get into your database. Then run:

db.createUser(
  {
    user: "mycollectionUser",
    pwd: "examplepass123",
    roles: [
       { role: "readWrite", db: "myDbName" }
    ]
  }
)

To remove an user:

db.dropUser("mycollectionUser")
0 0 votes
Article rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments