

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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”.
- Related Questions & Answers
- How do I change a MongoDB user's password?
- How to change the local user account password using PowerShell?
- How can we change MySQL user password by using the SET PASSWORD statement?
- How can we change MySQL user password by using the ALTER USER statement?
- What does % stand for in host column and how to change user's password?
- How to Force User to Change Password at Next Login in Linux?
- How can we change MySQL user password by using UPDATE statement?
- How to create MongoDB user on existing database with correct role?
- How to change user agent for Selenium driver?
- Check for Existing Document in MongoDB?
- Shifting values of rows in MySQL to change the existing id values for existing rows?
- How to reset or change the MySQL root password?
- How to change the user and group permissions for a directory using Python?
- Check for existing documents/embedded documents in MongoDB
- Set special characters for password while creating a new MySQL user?
Advertisements