当前位置:网站首页>Install and run mongodb under win10

Install and run mongodb under win10

2022-06-23 04:55:00 mercenary's L

Two 、 install

During installation , You can click "Custom( Customize )" Button to set your installation directory .

At this time, I will change the installation directory to D:\MongoDB

Next installation  "install mongoDB compass"  Don't check ( Of course, you can also choose to install it , It may take longer to install ),MongoDB Compass Is a graphical interface management tool , We can download and install it from the official website in the back , Download address :MongoDB Compass Download | MongoDB.

3、 ... and 、 Create a data directory

MongoDB Store data directory in db Under the table of contents . But this data directory will not be created actively , We need to create it after the installation , And then create the directory of database and log files .

1、 Create a data directory

2、 Create database and log files

Four 、 function MongoDB service 、 Connect MongoDB database .

Install well MongoDB After that, we first need to MongoDB The service has been improved , There are two ways to start a service .

1、 Start... From the command line MongoDB service

To run from the command prompt MongoDB The server , You have to go from MongoDB The directory bin Execute... In directory mongod.exe file .

D:\MongoDB\bin\mongod --dbpath d:\MongoDB\data\db

  I am here powerShell The effect of execution in is as follows  

 

  Connect from the command line MongoDB To test

  We can run it in a command window mongo.exe Command to connect MongoDB, Execute the following command :

D:\MongoDB\bin\mongo.exe
 
 I am here powerShell The effect of execution in is as follows , Connect to MongoDB Then we can enter db By default, the command view points to test database .

2、 Run by configuration MongoDB service

First step 、 Create a profile

Create a profile . The file must be set to systemLog.path Parameters , It's better to include some additional configuration options .

for example , Create a configuration file located in C:\MongoDB\mongod.cfg, It specifies systemLog.path and storage.dbPath. The specific configuration is as follows :

 

  The second step 、 install MongoDB service

Through execution mongod.exe, Use --install Option to install the service , Use --config Option to specify the previously created configuration file .( During installation powershell You must run as an administrator or the installation will not succeed )

D:\MongoDB\bin\mongod.exe --config "D:\MongoDB\mongod.cfg" --install

ps: Whether the installation is successful or not can be reached data\log\mongod.log In the file , If there is an error, you can also view the error reason here .

  The third step 、 start-up MongoDB service ( This is the time powershell Also as an administrator )

net start MongoDB

 I am here powershell The results of the operation in are as follows , After successful startup, you can windows There will be... In the service MongoDB The service is already running .

 

Next we can run in the command window as above mongo.exe Command to connect MongoDB, Carry out connection test , Execute the following command :

D:\MongoDB\bin\mongo.exe

 My operation results are as follows :

Step four 、 close MongoDB service ( This is the time powershell Also as an administrator )

net stop MongoDB

  remarks : The above two operations MongoDB Choose one of the methods , Create a with the second windows service , Don't hang it all the time powershell window .

原网站

版权声明
本文为[mercenary's L]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206222350089503.html