Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (50.2k points)

I want to set up my development environment on Windows by producing two batch files with the help of nginx/PHP/MongoDB stack. The following is my start.bat and stop.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

but I am not able to shutdown the MongoDB server...

1 Answer

0 votes
by (107k points)

The code 'use dbname' will not operate in scripted mode. What you can do is to explicitly specify the database in the connection.

And also, you can generate a connection within a script, refer the  following code:

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

You have to save the following code in stop_mongod.js file:

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

 db.shutdownServer();

 quit();

If needed you can adjust the connection string. Then from the batch script, run the following command:

mongo stop_mongod.js

If you are a beginner and want to know more about MongoDB, then do check out the MongoDB tutorial which will help you in learning MongoDB from scratch. 

Related questions

0 votes
2 answers
0 votes
2 answers
0 votes
1 answer
0 votes
2 answers
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...