Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop mongodb server on Windows?

Tags:

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

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 

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

like image 665
Vitaly Avatar asked Nov 01 '11 21:11

Vitaly


People also ask

How do I end a MongoDB session?

To run endSessions , use the db. runCommand( { <command> } ) method.

How do I stop MongoDB from opening on startup?

Go to your windows services. msc and set your mongoDB on manual. To start your DB open admin prompt net start mongodb . To stop it net stop mongodb .


2 Answers

I'm not sure that's a proper way to do, sending a kill could probably cause damage to your mongo server, and you'll need to repair your database after in case of crash.

Maybe you already solved this question but here is what I do :

mongo admin --eval "db.shutdownServer()" 

I'm automatically connected on the admin's collection and next, I just have to run the extinction.

Here is the official link about how to stop Mongodb properly : http://api.mongodb.org/wiki/current/Starting%20and%20Stopping%20Mongo.html

Best

like image 68
JulienD Avatar answered Oct 14 '22 16:10

JulienD


  1. Open Command Prompt/Powershell as Administrator.
  2. Execute "net stop MongoDB"
like image 21
Rut Shah Avatar answered Oct 14 '22 17:10

Rut Shah