(MongoDB) How to use –fork On Windows for multiple servers

Although for most of developers, deploying database On Windows is not advised. For beginners like me, always need do some practise on Windows.

Currently I am studying replica sets, which asks me to run multiple servers at the same time with following commands.

As we known, it is a Linux commands. Since the --fork option is not available in Windows, I guess this might be useful for Windows Users.

You can achieve the same effect through either of the following.

  1. Windows Command Shell users:

  1. Windows Powershell users:

Like me, I use Powershell, so the command is like following:

NOTE:

  • if mongod.exe is not in your PATH environment variable, you can subsitute “mongod” above with the entire path to mongod.exe (include mongod.exe to the end, of course)

  • examples above deliberately use double-quote punctuations to account for the possibility of space characters present in path for the mongod executable (if not already available in PATH environment variable) and log file location; if this (presence of spaces) does not apply to your situation, please ignore them

  • examples above assume knowledge of standard definitions for documenting syntax of commands for the following literals:
    "<" ">" "[" "]"
    so do not include them in your command

  • examples above reference “OptionArguments”, which may be of use under certain situations; for example, one of the useful Arguments could be
    --dbpath "path_to_your_db"
    if you, like me, don’t_like your db files to be at /data/db under the default drive

  • since mongod window is no longer available for you to press CTRL+C to to terminate the mongod server, you might have to spawn mongoshell (mongo.exe) and provide the following command to end the mongod server instance:

  • try above commands without running any other commands and take a look at the log file, it will help!

  • mongod server process can also be terminated by issuing the following command at command line:
    mongo admin --eval "db.shutdownServer()" [--port <nnnn>]
    where nnnn is the port where mongod is listening to (ignore this, if it is the default port 27017)

Leave a Reply

Your email address will not be published. Required fields are marked *