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
Oldest
Newest Most Voted
Inline Feedbacks
View all comments