
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
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 Articles
- 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?
- What does % stand for in host column and how to change user's password?
- How can we change MySQL user password by using the ALTER USER statement?
- How to Force User to Change Password at Next Login in Linux?
- How to create MongoDB user on existing database with correct role?
- How can we change MySQL user password by using UPDATE statement?
- 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 change password of users in Django?
- How to reset or change the MySQL root password?
- Check for existing documents/embedded documents in MongoDB
- How to change the user and group permissions for a directory using Python?

Advertisements