MongoError:无权执行命令 { find: "app_updates", filter: { key: "0.0.1-admins";}, limit: 1, batchSize: 1, singleBatch: true } [英] MongoError: not authorized on to execute command { find: "app_updates", filter: { key: "0.0.1-admins" }, limit: 1, batchSize: 1, singleBatch: true }
问题描述
我按照这种方法启动了一个 KeystoneJS 项目.但是进入项目根目录并运行 node keystone.js
后,我收到错误:
I start a KeystoneJS project following this method. But after entering the project root directory and running node keystone.js
I receive the error:
------------------------------------------------
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
包.
I researched on this error but I couldn't resolve it. I'm on OpenSUSE, and was working with nodejs8
package.
当我通过运行在 systemd 上启动 mongodb 时:
When I start the mongodb on systemd by running:
$ sudo systemctl start mongodb.service
...我收到上述错误.
... I receive the above error.
但是当我通过运行启动 mongodb 时:
But when I start the mongodb by running:
$ sudo mongod
...我没有收到任何错误,keystonejs 工作正常,我不知道为什么!
... I don't receive any error and keystonejs works fine, I'm not sure why!
当我通过运行 $ sudo mongod -f/etc/mongodb.conf
启动 mongodb 时,我收到上述错误.但是当我通过运行 $ sudo mongod
启动 mongodb 时,我没有收到任何错误.因此,看起来问题原因在 /etc/mongodb.conf
文件中,如下所示:
When I start mongodb by running $ sudo mongod -f /etc/mongodb.conf
I receive the above error. But When I start mongodb by running $ sudo mongod
, I don't receive any error. Therefore, looks like the problem cause is within the /etc/mongodb.conf
file which is as follows:
# 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
In your config you're using authorization for accessing Mongo
# Security settings.
security:
authorization: enabled
首先需要创建用户——打开mongo控制台(mongo)在没有配置的情况下启动 mongod
At first you need to create user - open mongo console (mongo) Start mongod without config
mongod --port 27017 --dbpath /data/db1
使用控制台连接到实例
mongo --port 27017
在 mongo 控制台输入下一个命令
in mongo console enter next commands
use admin
db.createUser(
{
user: "superAdmin",
pwd: "admin123",
roles: [ { role: "root", db: "admin" } ]
})
现在您可以通过配置访问 mongo 作为服务
Now you can access mongo using as a service with your config
mongo --port 27017 -u "superAdmin" -p "admin123" --authenticationDatabase "admin"
因此您需要通过创建具有读写权限的新用户来授予对 mongo 的访问权限
So you need to grant access to mongo by creating new user with ReadWrite permission
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"
And try to connect using this credentials mongo --port 27017 -u "myAppDbUser" -p "myApp123" --authenticationDatabase "myAppDb"
并使用此用户进行 keystone 配置以连接到 mongo,例如
and use this user for keystone config to connect to mongo, for example
mongodb://myAppDbUser:myApp123@localhost:27017/myAppDb
(通过 https://medium.com/@raj_adroit/mongodb-enable-authentication-enable-access-control-e8a75a26d332)
这篇关于MongoError:无权执行命令 { find: "app_updates", filter: { key: "0.0.1-admins";}, limit: 1, batchSize: 1, singleBatch: true }的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!