- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change the password in MongoDB for existing user?
To change the password in MongoDB for existing user, you can use changeUserPassword(). Following is the syntax
db.changeUserPassword("yourExistingUserName", "yourPassword");
Let us first switch the database to admin. Following is the syntax
> use admin
This will produce the following output
switched to db admin
Now, display users from the database. Following is the query
> db.getUsers();
This will produce the following output
[ { "_id" : "admin.John", "user" : "John", "db" : "admin", "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] } ]
Following is the query to change the password for user “John”
> db.changeUserPassword("John", "123456");
Now the password has been changed with value “123456”.
Advertisements