MongoDB v3.6.4 :从mongo 3.4迁移到3.6后
从shell中我可以启动数据库并通过身份验证连接到它。
mongod --auth --port 27017 --dbpath /data/db
但是,当我使用brew启动mongodb时,身份验证不起作用,也无法手动进行身份验证。
~ $ mongo
MongoDB shell version v3.6.4
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.4
> use admin
switched to db admin
> db.stats()
{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { dbstats: 1.0, scale: undefined, $db: \"admin\" }",
"code" : 13,
"codeName" : "Unauthorized"
}
> db.auth('superAdmin', 'password')
Error: Authentication failed.
0
如何使用auth运行mongodb作为服务?
可以通过在/usr/local/etc/mongod.conf文件中将授权设置为禁用来选择退出身份验证,但是运行具有所需权限的服务会很不错:
security:
authorization: disabled
完成,检查:
- The answer suggested here does not seem to be correct either - it is not a valid command
醇>brew services start mongodb --auth --port 27017 --dbpath /usr/local/var/mongodb