我正在尝试添加授权到我的MongoDB。 我使用MongoDB 2.6.1在Linux上完成所有这些工作。 我的mongo .conf文件是旧的兼容格式 (这就是安装的方式)。

1)我创建了admin用户,如(3)所述

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

2)然后我通过取消注释这一行来编辑mongo .conf

真实的

3)最后,我重启了mongod服务,并尝试登录:

/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 >>>

有什么问题吗?我把整个过程重复了三次 我想我做的都是在MongoDB文档中指定的。但这并不奏效。 我期望这个sa用户被授权做任何事情,以便 然后,他可以创建其他用户,并给予他们更具体的权限。

如何检查当前批处理脚本是否具有管理权限?

我知道如何使它调用自己与runas,但不知道如何检查管理权限。我所见过的唯一解决方案是粗糙的黑客工作或使用外部程序。好吧,其实我不在乎这是不是一份苦差事,只要它能在Windows XP或更新版本上运行就行。