- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 do I change a MongoDB user's password?
You need to use changeUserPassword() to change a user’s password. Let us first create a user with some roles. Following is the query to create a user in MongoDB −
> use admin switched to db admin > db.createUser( ... { ... user: "Chris", ... pwd: "chris", ... roles: [ { role: "readWrite", db: "test" } ] ... } ... ); Successfully added user: { "user" : "Chris", "roles" : [ { "role" : "readWrite", "db" : "test" } ] }
Let us display the user from test database −
> db.getUser("Chris");
This will produce the following output −
{ "_id" : "admin.Chris", "user" : "Chris", "db" : "admin", "roles" : [ { "role" : "readWrite", "db" : "test" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] }
Following is the query to change a MongoDB user's password.
> db.changeUserPassword("Chris", "123456");
The password has been changed.
- Related Articles
- What does % stand for in host column and how to change user's password?
- How to change the password in MongoDB for existing user?
- How do I change matplotlib's subplot projection of an existing axis?
- How can we change MySQL user password by using the SET PASSWORD statement?
- How do I change a tag's inner HTML based on their order in JavaScript?
- How can we change MySQL user password by using the ALTER USER statement?
- How to change the local user account password using PowerShell?
- How can we change MySQL user password by using UPDATE statement?
- How do I get into a Docker container's shell?
- How to Force User to Change Password at Next Login in Linux?
- How do I get time of a Python program's execution?
- How Do I Know Whether It's a Fungal Nail Infection?
- How do I redraw an image using Python's Matplotlib?
- Resolve error 1045 (28000) access denied for user 'root'@'localhost' (using password: YES)?
- How do I create a user interface through Python?

Advertisements