[MongoDB]: How do we change MongoDB user password

[root@dbversitydotcom bin]# cat /etc/mongod.conf
# MongoDB Configuration File

# General Settings
fork = true
quiet = true
smallfiles = true

# Logging
verbose = true
logappend = true
logpath = /opt/mongodb/mongod.log

# Security
auth = true

#setParameter = supportCompatibilityFormPrivilegeDocuments=0
#setParameter = logUserIds=1
#sslOnNormalPorts = true
#sslPEMKeyFile = /etc/ssl/mongodb.pem
#sslPEMKeyPassword = pass

#nohttpinterface = true
#bind_ip = xx.xxx.xx.xx
#noscripting = true
dbpath = /opt/mongodb/data
[root@dbversitydotcom bin]#
[root@dbversitydotcom bin]# numactl –interleave=all ./mongod -f /etc/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 664
all output going to: /opt/mongodb/mongod.log

child process started successfully, parent exiting
[root@dbversitydotcom bin]#
[root@dbversitydotcom bin]# ps -ef | grep mongo
root 664 1 12 07:33 ? 00:00:02 ./mongod -f /etc/mongod.conf
[root@dbversitydotcom bin]#
[root@dbversitydotcom bin]# mongo localhost:27017
MongoDB shell version: 2.4.11
connecting to: localhost:27017/test
>
>
> use admin
switched to db admin
>
>
> db.addUser({user:”adm”,pwd:”pwd”,roles:[“userAdminAnyDatabase”,”readAnyDatabase”,”clusterAdmin”]})
{
“user” : “adm”,
“pwd” : “8f1cf56da9da9e575e0c85ed1c5a4fba”,
“roles” : [
“userAdminAnyDatabase”,
“readAnyDatabase”,
“clusterAdmin”
],
“_id” : ObjectId(“547db209a26612060270fe4a”)
}
>
>

[root@dbversitydotcom bin]# mongo dbversitydotcom:27017/admin -u adm -p pwd
MongoDB shell version: 2.4.11
connecting to: dbversitydotcom:27017/admin
>
> show dbs
admin 0.0625GB
local 0.03125GB
>
> db.system.users.find()
{ “_id” : ObjectId(“547db209a26612060270fe4a”), “user” : “adm”, “pwd” : “8f1cf56da9da9e575e0c85ed1c5a4fba”, “roles” : [ “userAdminAnyDatabase”, “readAnyDatabase”, “clusterAdmin” ] }
>
>
> db.changeUserPassword(“adm”,”DBversity#123″)
>
> db.system.users.find()
{ “_id” : ObjectId(“547db209a26612060270fe4a”), “pwd” : “2d285ce06d634fa07013f7c74176ebbf”, “roles” : [ “userAdminAnyDatabase”, “readAnyDatabase”, “clusterAdmin” ], “user” : “adm” }
>
>
bye
[root@dbversitydotcom bin]# mongo dbversitydotcom:27017/admin -u adm -p pwd
MongoDB shell version: 2.4.11
connecting to: dbversitydotcom:27017/admin
Tue Dec 2 07:38:18.525 Error: 18 { code: 18, ok: 0.0, errmsg: “auth fails” } at src/mongo/shell/db.js:228
exception: login failed
[root@dbversitydotcom bin]#
[root@dbversitydotcom bin]#
[root@dbversitydotcom bin]# mongo dbversitydotcom:27017/admin -u adm -p DBversity#123
MongoDB shell version: 2.4.11
connecting to: dbversitydotcom:27017/admin
>
>
> show dbs
admin 0.0625GB
local 0.03125GB
>

  • Ask Question