在 Windows 上配置 MongoDB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24772428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Configuring MongoDB on Windows
提问by Jago
I am trying to set up MongoDB on Windows, and the online docs seem far from accurate.
我正在尝试在 Windows 上设置 MongoDB,但在线文档似乎不太准确。
Under "Configure a Windows Service" part, step 1mentions 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.
在“配置 Windows 服务”部分下,第 1 步提到了创建配置文件。然后它提到用格式的一行填充文件logpath="X:\path\mongo.log"
。但是,在链接之后,据说配置文件采用 YAML 格式,这使得前一行在 YAML 中不可读。
I have created a basic mongodb.cfg
(.cfg
or .conf
??) file:
我创建了一个基本mongodb.cfg
(.cfg
或.conf
??)文件:
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
However when I start mongod --config P:\Servers\MongoDB\mongodb.cfg
, the service just won't give any output at all, and just hangs.
但是,当我开始时mongod --config P:\Servers\MongoDB\mongodb.cfg
,该服务根本不会提供任何输出,只是挂起。
If I remove the dbPath
line, it will just close itself with no message at all.
如果我删除该dbPath
行,它只会关闭自己,根本没有任何消息。
I have also tried to leave the mongodb.cfg
file just like this:
我也试过mongodb.cfg
像这样离开文件:
logpath="P:\Servers\MongoDB\logs\mongodb.log"
dbpath="P:\Servers\MongoDB\data"
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.
但是执行会中止抱怨 2 条路径中的任何一条,即使它们存在。尝试使用单个反斜杠和转义反斜杠 ( \\
) 没有成功。
The only way the service works and listens for connections is to manually pass --dbpath
only, and ignore any config file and logpathat 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.
该服务工作和侦听连接的唯一方法是--dbpath
仅手动传递,并完全忽略任何配置文件和日志路径。显然这并不严重,因为我需要跟踪日志,并且可能需要在以后更改配置参数。
This is nuts... Am I missing something very basic or this docs are a real mess?
这太疯狂了......我是否遗漏了一些非常基本的东西,或者这个文档真的一团糟?
回答by wbdarby
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.
这是我用于 Windows 的简单测试 MongoDB 配置文件。请注意,我必须在每个属性前有 2 个空格,例如路径。当我有 3 个空格时,我在启动时出错。
I start the server with: mongod --config c:\tools\mongodb\db\mongod.cfg
我用以下命令启动服务器: 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
回答by Adam Mendoza
Here's an example of a mongodb.config file for Windows.
这是 Windows 的 mongodb.config 文件的示例。
##store data here
dbpath=C:\mongodb\data\db
##all output go here
logpath=C:\mongodb\data\log\mongo.log
##log read and write operations
diaglog=3
回答by devman81
Bit late but I had the exact same issue today. If you use forward slashes for your paths within the config file it works fine.
有点晚了,但我今天遇到了完全相同的问题。如果您在配置文件中为路径使用正斜杠,则它可以正常工作。
systemLog:
destination: file
logAppend: true
path: "e:/mongo_data/3.6/mongo.log"
storage:
dbPath: "e:/mongo_data/3.6/db"
engine: "wiredTiger"
systemLog:
destination: file
logAppend: true
path: "e:/mongo_data/3.6/mongo.log"
storage:
dbPath: "e:/mongo_data/3.6/db"
engine: "wiredTiger"
回答by Alexey Lagunov
For those who installed via *.msi installer and wondering where is .conf file located. Run 'services.msc' and check properties of mongodb service runnable file.
对于那些通过 *.msi 安装程序安装并想知道 .conf 文件位于何处的人。运行“services.msc”并检查 mongodb 服务可运行文件的属性。
回答by ravi
check if you have any file in data\db path. Please remove all those files and try to restart. I exactly used your config file and able to start the service successfully with bindip and port
检查 data\db 路径中是否有任何文件。请删除所有这些文件并尝试重新启动。我完全使用了您的配置文件,并且能够使用 bindip 和 port 成功启动服务
回答by Ivan Shesterkin
You can find logs with reasons why it's not working in log file. In your case, read P:\Servers\MongoDB\logs\mongodb.log file.
您可以在日志文件中找到原因不明的日志。在您的情况下,请阅读 P:\Servers\MongoDB\logs\mongodb.log 文件。