SoFunction
Updated on 2024-07-15

Three ways to start the database MongoDB

Method 1. Original startup method: cmd + cd to the installation path

  • cmd command line cd to the installation path:cd C:\Program Files\MongoDB\Server\3.4\bin

  • Then cmd start MongoDB and execute the cmd command: --dbpath E:\db\MongoDB

Method 2. Slightly more advanced startup: modification to add PC global variables

  • "Desktop" = "My Computer" + Right mouse button select "Properties" = "Advanced System Properties "=" "Environment Variables" =" "Global Variables" =" Modify "Path"Information on the path of the variable [increasepreceding part of the textMethod1cd to the installation path [cd C:\Program Files\MongoDB\Server\3.4\bin]】

    Note: Because the variable path is a string, if there are multiple paths, then a semicolon should be used between paths.; Spacing out.

  • Then, open cmd and execute the command:mongod

  • Finally, cmd executes the command:mongod --dbpath E:\db\MongoDB

The specific implementation of Method2 is shown in the screenshot below:

But you still have to enter a long piece of code like mongod --dbpath E:\db\MongoDB.
It's still a pain in the ass! That's why the following method (i.e.: start the MongoDB database service using a batch file) was created.

Method 3. Very advanced startup: custom .bat batch file

  • immediately aboveMethod 2Modified global variablespath After the variable path of the

  • Locally, create a new text document and change the file suffix to:.batDocumentation (batch file);

    .bat file naming: no spaces can appear, as far as possible in English, you can use the underscore interval.

  • Notepad++ Open the .bat batch file, add the following code and save the file;

echo "MongoDB starting.........."
mongod --dbpath E:\db\MongoDB
pause
  • keyboarddouble-clickThis batch file, normally, starts the MongoDB database service quickly.

If it fails to start properly, double check and troubleshoot the following problems:

  • Is the path variable path normalized?
  • Does the .bat file name contain spaces and is it standardized?
  • .bat file internal code, is it correct?
  • Is the browser address correct?
    The default should be localhost:27017/ or http://127.0.0.1:27017/
  • Browser a little slow to respond?
    Wait a little while for the page to finish refreshing and then check the results

Troubleshooting the above issues should essentially fix the boot failure.

to this article on the database MongoDB startup of the three ways to this article, more related to MongoDB startup mode content please search my previous posts or continue to browse the following related articles I hope you will support me in the future more!