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.



db.changeUserPassword(username, password)


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

See also  How to return only specific fields from a MongoDB query?

Leave a Reply

Your email address will not be published.

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