在Windows上配置MongoDB [英] Configuring MongoDB on Windows
问题描述
我正在尝试在Windows上设置MongoDB,在线文档似乎远远不够准确.
I am trying to set up MongoDB on Windows, and the online docs seem far from accurate.
在配置Windows服务"部分下,格式的行填充文件.但是,在链接之后,该配置文件被称为YAML格式,这使得前一行在YAML中不可读.
Under "Configure a Windows Service" part, step 1 mentions to create a config file. Then it mentions to fill in the file with a line in the format logpath="X:\path\mongo.log"
. However, following the link, the config file is said to be in YAML format, which renders the previous line unreadable in YAML.
我已经创建了一个基本的mongodb.cfg
(.cfg
或.conf
??)文件:
I have created a basic mongodb.cfg
(.cfg
or .conf
??) file:
systemLog:
destination: file
path: "P:\\Servers\\MongoDB\\logs\\mongodb.log"
quiet: true
logAppend: true
storage:
dbPath: "P:\\Servers\\MongoDB\\data"
journal:
enabled: true
net:
bindIp: 127.0.0.1
port: 27017
但是,当我启动mongod --config P:\Servers\MongoDB\mongodb.cfg
时,该服务根本不会给出任何输出,而只是挂起.
However when I start mongod --config P:\Servers\MongoDB\mongodb.cfg
, the service just won't give any output at all, and just hangs.
如果我删除dbPath
行,它只会自动关闭,完全没有消息.
If I remove the dbPath
line, it will just close itself with no message at all.
我也试图像这样离开mongodb.cfg
文件:
I have also tried to leave the mongodb.cfg
file just like this:
logpath="P:\Servers\MongoDB\logs\mongodb.log"
dbpath="P:\Servers\MongoDB\data"
但是执行会中止抱怨这2条路径中的任何一条,即使它们存在.尝试使用单个反斜杠和转义的反斜杠(\\
),但均未成功.
But execution aborts complaining about any of the 2 paths, even tho they exist. Tried with single backslashes and with escaped backslashes (\\
) with no success.
服务工作和侦听连接的唯一方法是仅手动传递--dbpath
,并且完全忽略任何配置文件和日志路径.显然,这并不严重,因为我需要跟踪日志,并且以后可能还需要更改配置参数.
The only way the service works and listens for connections is to manually pass --dbpath
only, and ignore any config file and logpath at all. Obviously this is not serious, as I need to keep track of the logs and also might need to change config parameters at some later point.
这太疯狂了……我是否缺少一些非常基本的内容,或者该文档确实是一团糟?
This is nuts... Am I missing something very basic or this docs are a real mess?
推荐答案
这是我用于Windows的简单测试MongoDB Config文件.请注意,每个属性之前都必须有2个空格,例如path.当我有3个空格时,在启动时出现错误.
Here is my simple test MongoDB Config file for Windows. Note that I had to have 2 spaces before each property, e.g., path. When I had 3 spaces I got an error at startup.
我使用以下命令启动服务器:mongod --config c:\tools\mongodb\db\mongod.cfg
I start the server with: mongod --config c:\tools\mongodb\db\mongod.cfg
systemLog:
destination: file
path: "C:\\tools\\mongodb\\db\\log\\mongo.log"
logAppend: true
storage:
dbPath: "C:\\tools\\mongodb\\db\\data"
security:
authorization: enabled
这篇关于在Windows上配置MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!