errmsg" : "not authorized on book to execute command

来源:互联网 发布:淘宝怎么装修模板 编辑:程序博客网 时间:2024/04/30 23:27

接上一篇博客,安装好了mongodb,然后进行建库,插入数据,更新数据等一系列操作

上篇文章的链接:http://blog.csdn.net/sizhezhongnian/article/details/74002537


建数据库

use  xxx

当有xxx库的时候,则不创建新的,当没有xxx的时候,自动创建xxx数据库

use book


新增数据

db.book.insert({"name":"cjn","age":24,"sex":"男"});

当执行时,出错


此时

MongoDB进行操作时,出现errmsg" : "not authorized on test to execute command { listCollections: 1.0 }这个提示

表示没有权限,那就赶紧添加用户吧

切换到admin库

use admin;


添加用户
db.createUser( {
    user: "sa",
    pwd: "sa",
    roles: [ { role: "root", db: "admin" } ]
  });


既然已经添加了用户

用sa账号登录

db.auth('sa','sa');


然后在

db.book.insert({"name":"cjn","age":24,"sex":"男"});



成功!




阅读全文
0 0
原创粉丝点击