如何在mongodb配置文件中设置授权?

mli*_*bre 38 authentication configuration-files mongodb

mongod.exe使用此选项在服务器中运行cmd.exe:

mongod.exe --dbpath=path --auth
Run Code Online (Sandbox Code Playgroud)

现在,我如何在配置文件中执行此操作?
我的mongod.cfg:

dbpath=D:\Program Files\MongoDB 2.6 Standard\data

security=
authorization= enabled
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

解析INI配置文件时出错:未知选项安全性.

kei*_*ics 23

mongodb版本3.2

这是正确的配置

security:
  authorization: "enabled"
Run Code Online (Sandbox Code Playgroud)

带引号,因为该值是根据文档的字符串


Rob*_*ers 9

security:
   authorization: "enabled"
Run Code Online (Sandbox Code Playgroud)

这是正确的,如上所述,有一点需要注意的是,如果它仍然不起作用,请确保您没有使用选项卡作为授权行,它将无法工作,您只需要使用空格.


Mal*_*och 8

只需要说

auth=true
Run Code Online (Sandbox Code Playgroud)

您不需要任何其他选项!


小智 6

如果您使用 YAML

security:
  authorization: "enabled"
Run Code Online (Sandbox Code Playgroud)

适用于 2.6 或更高版本。

但如果你不使用YAML。

auth: true
Run Code Online (Sandbox Code Playgroud)

我使用 mongodb v3.0.2、v3.6.5、v4.0.3,两个文件都工作正常。

配置文件

# mongodb.conf

# Where to store the data.
dbpath=/var/lib/mongodb

#where to log
logpath=/var/log/mongodb/mongodb.log

logappend=true

bind_ip = 0.0.0.0
port = 27017

journal=true
auth = true
Run Code Online (Sandbox Code Playgroud)

YAML 配置

# 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
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

security:
  authorization: "enabled"

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:
Run Code Online (Sandbox Code Playgroud)