本文介绍了如何在Windows上停止mongodb服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用nginx/PHP/MongoDB堆栈,并试图通过创建两个批处理文件在Windows上设置我的开发环境.

I'm using the nginx/PHP/MongoDB stack and trying to set up my development environment on Windows by creating two batch files.

start.bat

start.bat

cd C:\www\nginx
start nginx
cd C:\www\php
start php-cgi.exe -b 127.0.0.1:9000
cd C:\www\mongodb
start mongod

stop.bat

cd C:\www\nginx
nginx -s quit
cd C:\www\php
taskkill /F /IM php-cgi.exe
cd C:\www\mongodb
mongo --eval "use admin; db.shutdownServer(); quit"  # this doesn't work
mongo --eval stop_mongod.js  # this doesn't work either

不能使用taskkill停止mongod,因为这可能会导致数据损坏.有什么建议吗?

Using taskkill to stop mongod isn't an option, since that may lead to data corruption.Any suggestions?

推荐答案

从mongo shell 文档:

From the mongo shell documentation:

使用dbname

此命令在脚本模式下不起作用.相反,您将需要在连接中显式定义数据库(上例中为/dbname).

This command does not work in scripted mode. Instead you will need to explicitly define the database in the connection (/dbname in the example above).

或者,您也可以在脚本中创建连接:

Alternately, you can also create a connection within the script:

db2 = connect("server:27017/otherdbname")


我想出了以下代码:将以下代码段保存在 stop_mongod.js 文件中:


I've come up with the following code:Save the following snippet in stop_mongod.js file:

 db = connect("localhost:27017/admin");
 db.shutdownServer();
 quit();

如有必要,请调整连接字符串.然后从命令行或在批处理脚本中:

Adjust the connection string if necessary. Then from the command line or within your batch script:

mongo stop_mongod.js

这篇关于如何在Windows上停止mongodb服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:53
查看更多