Home > Database > Mysql Tutorial > mongodb 修改用户密码 2种方法

mongodb 修改用户密码 2种方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:32:51
Original
1378 people have browsed it

mongodb的用户信息是存放在system.users表中的,修改密码不能直接更新表数据,这样的话,存到表里的密码是明文的,这就不对了。 1,错误做法,直接更新表 db.system.users.update({"_id" : ObjectId("529e67553992b24438d5e315")},{"user":"tank2","readOnly"

mongodb的用户信息是存放在system.users表中的,修改密码不能直接更新表数据,这样的话,存到表里的密码是明文的,这就不对了。

1,错误做法,直接更新表

> db.system.users.update({"_id" : ObjectId("529e67553992b24438d5e315")},{"user":"tank2","readOnly" : false,"pwd":"123"})
> db.system.users.find();
{ "_id" : ObjectId("529e5f8474b4c660718a70f3"), "user" : "tank1", "readOnly" : false, "pwd" : "35dd47abff098f5b4f0b567db8edeac5" }
{ "_id" : ObjectId("529e67553992b24438d5e315"), "user" : "tank2", "readOnly" : false, "pwd" : "123" }  //这样就不对了
Copy after login

2,正确做法,利用db.addUser

> db.addUser('tank2','111')
{
?? ?"_id" : ObjectId("529e6f1c8d95afd190add450"),
?? ?"user" : "tank2",
?? ?"readOnly" : false,
?? ?"pwd" : "6b4334d2c97c526e6a11b2f9ce1996e0"
}
Copy after login

有人会问,这个不是添加用户的方法吗。不错这是添加用户的方法,但是如果用户名相同,密码不同的话,就会更新密码。

3,正确做法,利用db.changeUserPassword

> db.changeUserPassword('tank2','test');
Copy after login
mongodb 修改用户密码 2种方法 mongodb的用户信息是存放在system.users表中的,修改密码不能直接更新表数据,这样的话,存到表里的密码是明文的,这就不对了。 1,错误做法,直接更新表 > db.system.users.update({"_id" : ObjectId("529e67553992b24438d5e315")},{"user":"tank2","readOnly" : false,"pwd":"123"}) > db.system.users.find(); { "_id" : ObjectId("529e5f8474b4c660718a70f3"), "user" : "tank1", "readOnly" : false, "pwd" : "35dd47abff098f5b4f0b567db8edeac5" } { "_id" : ObjectId("529e67553992b24438d5e315"), "user" : "tank2", "readOnly" : false, "pwd" : "123" } //这样就不对了 2,正确做法,利用db.addUser > db.addUser('tank2','111') { ?? ?"_id" : ObjectId("529e6f1c8d95afd190add450"), ?? ?"user" : "tank2", ?? ?"readOnly" : false, ?? ?"pwd" : "6b4334d2c97c526e6a11b2f9ce1996e0" } 有人会问,这个不是添加用户的方法吗。不错这是添加用户的方法,但是如果用户名相同,密码不同的话,就会更新密码。 3,正确做法,利用db.changeUserPassword > db.changeUserPassword('tank2','test');mongodb 修改用户密码 2种方法
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
mongodb start
From 1970-01-01 08:00:00
0
0
0
linux - ubuntu14 error installing mongodb
From 1970-01-01 08:00:00
0
0
0
Use of symfony2 mongodb
From 1970-01-01 08:00:00
0
0
0
mongodb _id rename
From 1970-01-01 08:00:00
0
0
0
Parameter understanding of mongodb
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template