我正在try 向我的MongoDB添加授权

1) 我创建了管理员用户,如(3)中所述

http://docs.mongodb.org/manual/tutorial/add-user-administrator/

2) 然后我编辑了mongod.取消注释这一行

auth = true

3) 最后,我重新启动了mongod服务,并try 登录:

/usr/bin/mongo localhost:27017/admin -u sa -p pwd

4) 我可以连接,但它在连接时这样说.

MongoDB shell version: 2.6.1
connecting to: localhost:27017/admin
Welcome to the MongoDB shell!
The current date/time is: Thu May 29 2014 17:47:16 GMT-0400 (EDT)
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }

5) 现在看来,我创建的这sa个用户根本没有权限.

root@test02:~# mc
MongoDB shell version: 2.6.1
connecting to: localhost:27017/admin
Welcome to the MongoDB shell!
The current date/time is: Thu May 29 2014 17:57:03 GMT-0400 (EDT)
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }
[admin] 2014-05-29 17:57:03.011 >>> use admin
switched to db admin
[admin] 2014-05-29 17:57:07.889 >>> show collections
2014-05-29T17:57:10.377-0400 error: {
        "$err" : "not authorized for query on admin.system.namespaces",
        "code" : 13
} at src/mongo/shell/query.js:131
[admin] 2014-05-29 17:57:10.378 >>> use test
switched to db test
[test] 2014-05-29 17:57:13.466 >>> show collections
2014-05-29T17:57:15.930-0400 error: {
        "$err" : "not authorized for query on test.system.namespaces",
        "code" : 13
} at src/mongo/shell/query.js:131
[test] 2014-05-29 17:57:15.931 >>>

What is the problem? I repeated this whole procedure 3 times and
I think I did it all as specified in the MongoDB docs. But it doesn't work.
I was expecting this 100 user to be authorized to do anything so that
he can then create other users and give them more specific permissions.

推荐答案

在添加第一个管理员用户时,我将角色设置为root之后,我也对同样的问题感到困惑,一切都正常了.

use admin
db.createUser(
  {
    user: 'admin',
    pwd: 'password',
    roles: [ { role: 'root', db: 'admin' } ]
  }
);
exit;

如果您已经创建了admin用户,您可以这样更改角色:

use admin;
db.grantRolesToUser('admin', [{ role: 'root', db: 'admin' }])

有关完整的身份验证设置参考,请参阅我在互联网上经过数小时研究后编辑的steps篇文章.

Mongodb相关问答推荐

如何在Mongo Aggregate Query中创建集合的对象ID数组,并在列表中查找另一个集合中的ID

在MogoDB中按时间间隔分组、统计文档和获取间隔时间

我们可以在Mongoose中这样使用Unique:[True,";This to Unique&qot;]吗

如何填充Mongoose中的嵌套引用

所有文档中嵌套 struct 中的条件匹配-mongodb

从具有多个数组匹配 MongoDB 的两个集合中采样数据

如何更新mongo中列表最后一个对象的属性

映射数组导致 mongodb 聚合

Stripe:必须提供来源或客户

MongoDB 中 cursor.count() 和 cursor.size() 之间的区别

使用 MongoDB 进行分页

MongoDB 存储 ObjectId 的数组

MEAN 堆栈文件上传

遍历所有 Mongo 数据库

如何在 MongoDB Map-reduce 映射函数中使用变量

MongoDB的数据库管理工具

判断 mongoDB 是否连接

如何从 Mongoose 模型对象中获取集合名称

缩短 MongoDB 属性名称值得吗?

带有 either or查询的mongoose findOne