Skip to content

How to change MongoDB user password in Mongo shell?

In Mongo shell db.changeUserPassword() shell method is used to change the password of the currently logged in user.

Advertisements

Syntax

db.changeUserPassword(username, password)
Advertisements

Example

# mongo
MongoDB shell version v4.0.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.2
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	http://docs.mongodb.org/
Questions? Try the support group
	http://groups.google.com/group/mongodb-user
    
> use admin
switched to db admin
> db.auth('admin','oldPassword')
1
> db.changeUserPassword("admin", "newPassword")
> 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.