我在this method之后开始了一个KeystoneJS项目。但进入项目根目录并运行node keystone.js
后,我收到错误:
------------------------------------------------
An error occurred applying updates, bailing on Keystone init.
Error details:
MongoError: not authorized on <KeystoneJS project name> to execute command { find: "app_updates", filter: { key: "0.0.1-admins" }, limit: 1, batchSize: 1, singleBatch: true }
我研究了这个错误,但我无法解决它。我在使用OpenSUSE,正在使用nodejs8
包。
当我通过运行启动systemd上的mongodb:
$ sudo systemctl start mongodb.service
...我收到上述错误。
但是当我通过运行启动mongodb时:
$ sudo mongod
...我没有收到任何错误,keystonejs工作正常,我不知道为什么!
当我通过运行$ sudo mongod -f /etc/mongodb.conf
启动mongodb时,我收到上述错误。但是当我通过运行$ sudo mongod
启动mongodb时,我没有收到任何错误。因此,看起来问题原因是在/etc/mongodb.conf
文件中,如下所示:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
#dbPath: /data/db/
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# Where and how to log messages.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
logRotate: reopen
# What type of connections to allow.
net:
port: 27017
bindIp: 127.0.0.1
ipv6: true
http:
enabled: false
JSONPEnabled: false
RESTInterfaceEnabled: false
# How to manage mongod.
processManagement:
fork: true
# Security settings.
security:
authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
在您的配置中,您使用授权访问Mongo
# Security settings.
security:
authorization: enabled
首先你需要创建用户 - 打开mongo控制台(mongo)启动mongod而不配置
mongod --port 27017 --dbpath /data/db1
使用控制台连接到实例
mongo --port 27017
在mongo控制台中输入下一个命令
use admin
db.createUser(
{
user: "superAdmin",
pwd: "admin123",
roles: [ { role: "root", db: "admin" } ]
})
现在,您可以使用配置作为服务来访问mongo
mongo --port 27017 -u "superAdmin" -p "admin123" --authenticationDatabase "admin"
因此,您需要通过创建具有读写权限的新用户来授予对mongodb的访问权限
use myAppDb #its name of your Database
db.createUser(
{
user: "myAppDbUser", #desired username
pwd: "myApp123", #desired password
roles: [ "readWrite"]
})
并尝试使用此凭据连接mongo --port 27017 -u“myAppDbUser”-p“myApp123”--authenticationDatabase“myAppDb”
例如,将此用户用于keystone配置以连接到mongo
mongodb://myAppDbUser:myApp123@localhost:27017/myAppDb
(通过https://medium.com/@raj_adroit/mongodb-enable-authentication-enable-access-control-e8a75a26d332)