mongodb 如何修复我的mongodb?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9953295/
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
How to repair my mongodb?
提问by marko
I can't seem to connect to Mongo DB, which I've installed as a Windows Service on my local machine. I've also built a little WPF application which communicates with MongoDB. The errormessage:
我似乎无法连接到 Mongo DB,我已将其作为 Windows 服务安装在本地计算机上。我还构建了一个与 MongoDB 通信的小 WPF 应用程序。错误信息:
Error: couldn't connect to server 127.0.0.1 shell/mongo.js:8 4 exception: connect failed Unclean shutdown detected.
错误:无法连接到服务器 127.0.0.1 shell/mongo.js:8 4 异常:连接失败检测到异常关闭。
回答by Sergio Tulentsev
You should launch it with --repair
flag.
你应该用--repair
标志启动它。
mongod --repair
After repair is finished, stop this one and launch it normally. Documentation on --repair option.
修复完成后,停止这个并正常启动它。关于 --repair 选项的文档。
回答by Moin Haidar
Quicker:
更快:
sudo rm /data/db/mongod.lock
sudo mongod --dbpath /data/db --repair
sudo mongod --dbpath /data/db
回答by Anubis
If you do a repair operation as root user be sure that afterwards all db files are owned by the mongodb user, otherwise mongodb will not start
如果您以root用户身份进行修复操作,请确保之后所有db文件都归mongodb用户所有,否则mongodb将无法启动
chown -R mongodb:mongodb /data/db
rm /data/db/mongod.lock
/etc/init.d/mongodb start
回答by Ivan Trechyokas
$ mongo
> use dbname
> db.repairDatabase()
Note--repair functionality is also available in the shell with the db.repairDatabase() helper for the repairDatabase command.
注意--repair 功能也可在 shell 中使用 db.repairDatabase() 帮助程序用于 repairDatabase 命令。
See also http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/:
另请参阅http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/:
回答by Sushil Paudel
Write the command as below and I think it will solve the problem:
编写如下命令,我认为它可以解决问题:
cd data/
rm -rf mongod.lock*
cd ..
mongod --repair
./mongod
回答by Tadele Ayelegn
Follow this step to restart your mondoDB as fresh
按照此步骤重新启动您的 mondoDB 作为新的
1, Kill all the processes that mongod is running
1、杀死mongod正在运行的所有进程
to do this forcefully kill each process that are running on port 27017(default port for mongodb)
lsof -n -i4TCP:27017
Where 27017 is the port number the process is running atthis returns the process id(PID) and run
kill -9 "PID"
Replace PID with the number you get after running the first command
为此,强制终止在端口 27017(mongodb 的默认端口)上运行的每个进程
lsof -n -i4TCP:27017
其中 27017 是进程运行的端口号这将返回进程 id(PID) 并运行
kill -9 "PID"
用运行第一个命令后得到的数字替换 PID
2, restart mongo using mongod
command
2、使用mongod
命令重启mongo