【转】MongoDB:用户认证(2)
> db.addUser('skytf_select','skytf_select',true); { "user" : "skytf_select", "readOnly" : true, "pwd" : "e344f93a69f20ca9f3dfbc40da4a3082", "_id" : ObjectId("50ad71c7d114dcf18a8bb221") } > db.system.users.find();db.system.users.find(); |
备注:只需在 addUser 命令中增加第三个参数,并指定为“true” ,即可创建只读帐号。
--3.2 测试
[mongo@redhatB data]$ mongo 127.0.0.1/skytf -u skytf_select -p MongoDB shell version: 2.2.1 Enter password: connecting to: 127.0.0.1/skytf > show collections; > db.test_5.find(); > db.test_5.save({id:3}); |
备注:以只读帐号 skytf_select 登陆库 skytf,有权限执行查询操作,没有权限执行插入操作;
四 附 命令参考
--4.1 db.addUserParameters:
|
Use this function to create new database users, by specifying a username and password as arguments
to the command. If you want to restrict the user to have only read-only privileges, supply a true third
argument; however, this defaults to false。
|
Allows a user to authenticate to the database from within the shell. Alternatively use mongo
--username and --password to specify authentication credentials.
五 参考
http://docs.mongodb.org/manual/tutorial/control-access-to-mongodb-with-authentication/
http://docs.mongodb.org/manual/administration/security/
http://blog.163.com/dazuiba_008/blog/static/36334981201110311534143/
转自 http://francs3.blog.163.com/blog/static/405767272012102331445410/