Install MongoDB on window platform
MongoDB Download
MongoDB provides precompiled binary packages for 32-bit and 64-bit systems. You can download and install them from the MongoDB official website. MongoDB pre- Compiled binary package download address: http://www.mongodb.org/downloads
Note: Windows XP system is no longer supported after MongoDB2.2 version.
MongoDB for Windows 64-bit Suitable for 64-bit Windows Server 2008 R2, Windows 7, and the latest version of Windows system.
MongoDB for Windows 32-bit Suitable for 32-bit Window systems and the latest Windows Vista. The maximum MongoDB database size is 2GB on 32-bit systems.
MongoDB for Windows 64-bit Legacy Suitable for 64-bit Windows Vista, Windows Server 2003, and Windows Server 2008.
Download the 32-bit or 64-bit .msi file according to your system. After downloading, double-click the file and follow the instructions to install it.
During the installation process, you can set your installation directory by clicking the "Custom" button.
##Create data directory
MongoDB will The data directory is stored under the db directory. However, this data directory will not be automatically created. We need to create it after the installation is completed. Please note that the data directory should be placed in the root directory (such as: C:\ or D:\, etc.). In this tutorial, we have installed mongodb on the C: drive, now let us create A data directory and then create a db directory in the data directory.c:\>cd c:\ c:\>mkdir data c:\>cd data c:\data>mkdir db c:\data>cd db c:\data\db>You can also create these directories through the window's explorer, not necessarily through the command line.
Running the MongoDB server from the command line
In order to run the MongoDB server from the command prompt, you must execute the mongod.exe file from the bin directory of the MongoDB directory
mongod.exe --dbpath c:\data\db
If the execution is successful. , the following information will be output:
2015-09-25T15:54:09.212+0800 I CONTROL Hotfix KB2731284 or later update is not installed, will zero-out data files 2015-09-25T15:54:09.229+0800 I JOURNAL [initandlisten] journal dir=c:\data\db\j ournal 2015-09-25T15:54:09.237+0800 I JOURNAL [initandlisten] recover : no journal fil es present, no recovery needed 2015-09-25T15:54:09.290+0800 I JOURNAL [durability] Durability thread started 2015-09-25T15:54:09.294+0800 I CONTROL [initandlisten] MongoDB starting : pid=2 488 port=27017 dbpath=c:\data\db 64-bit host=WIN-1VONBJOCE88 2015-09-25T15:54:09.296+0800 I CONTROL [initandlisten] targetMinOS: Windows 7/W indows Server 2008 R2 2015-09-25T15:54:09.298+0800 I CONTROL [initandlisten] db version v3.0.6 ……
Run the MongoDB server as a Windows service
Please note that you must have administrative rights to run the following command. The MongoDB server runs as a Windows service:
mongod.exe --bind_ip yourIPadress --logpath "C:\data\dbConf\mongodb.log" --logappend --dbpath "C:\data\ db" --port yourPortNumber --serviceName "YourServiceName" --serviceDisplayName "YourServiceName" --install
The following table is the parameter description for mongodb startup:
Parameter | Description |
---|---|
--bind_ip | Bind service IP. If bound to 127.0.0.1, it can only be accessed locally. If not specified, the default local IP |
- -logpath | Determine the MongoDB log file. Note that the specified file is not a directory |
--logappend | Use the append method to write the log |
--dbpath | Specify the database path |
--port | Specify the service port number, the default port is 27017 |
--serviceName | Specify the service name |
--serviceDisplayName | Specify the service name, how many Executed when serving a mongodb service. |
--install | Specify to install as a Windows service. |
MongoDB background management Shell
If you need to enter the MongoDB background management, you need to first open the bin under the mongodb installation directory directory, and then execute the mongo.exe file. MongoDB Shell is the interactive Javascript shell that comes with MongoDB, an interactive environment used to operate and manage MongoDB.
When you enter the mongoDB backend, it will link to the test document (database) by default:
> mongo MongoDB shell version: 3.0.6 connecting to: test ……
Since it is a JavaScript shell, you can run some simple arithmetic operations:
> 2 + 2 4 >
db Command is used to view the document (database) of the current operation:
> db test >
Insert some simple records and find it:
> db.php.insert({x:10}) WriteResult({ "nInserted" : 1 }) > db.php.find() { "_id" : ObjectId("5604ff74a274a611b0c990aa"), "x" : 10 } >
First command Insert the number 10 into the x field of the php collection.