MongoDB Download
MongoDB provides a precompiled binary package for 32-bit and 64-bit systems that you can download from MongoDB website, MongoDB precompiled binary package download address: http://www.mongodb.org/downloads
Note: The Windows XP system is no longer supported after the MongoDB2.2 version.
· The MongoDB for Windows 64-bit is suitable for 64-bit Windows Server 2008 R2, Windows 7, and the latest version of the Window system.
· The MongoDB for Windows 32-bit is suitable for the 32-bit Window system and the latest Windows Vista. The maximum number of MongoDB databases on 32-bit systems is 2GB.
· The MongoDB for Windows 64-bit Legacy is 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, download and double-click the file, and install it as prompted.
During installation, you can set up your installation directory by clicking on the Custom button.
Create a Data directory
MongoDB stores the data directory in the DB directory. But this data directory will not be actively created, we need to create it after the installation is complete. Note that the data directory should be placed under the root directory (such as: C:\ or D:\. , etc.).
In this tutorial, we've installed MongoDB on the C: disk, now let's create a directory of data and then create the 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.
Run MongoDB server under command line
In order to run the MongoDB server from a command prompt, you must execute the Mongod.exe file from the MongoDB directory's Bin directory.
Mongod.exe--dbpath c:\data\db
32-bit system use: Mongod.exe--dbpath c:\data\db--storageengine=mmapv1
If the execution succeeds, the following information is exported:
2015-09-25t15:54:09.212+0800 I Control Hotfix KB2731284 or later update isn't
installed, would 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
......
Running the MongoDB server as a Windows service
Please note that you must have administrative privileges to run the following command. Run the MongoDB server as a Windows service by executing the following command:
Create a file First: C:\data\dbConf\mongodb.log
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 describes the parameters that are started by MongoDB:
Parameters |
Describe |
--bind_ip |
Binding service IP, if bound 127.0.0.1, only native access, do not specify default local all IP |
--logpath |
Fixed MongoDB log file, note that the specified file is not a directory |
--logappend |
Write a log using an Append method |
--dbpath |
Specifying the database path |
--port |
Specify the service port number, default port 27017 |
--servicename |
Specify Service Name |
--servicedisplaynam |
Specifies the service name, which is executed when multiple MongoDB services are available. |
--install |
Specifies to be installed as a Windows service. |
MongoDB Background Management Shell
If you need to enter MongoDB admin, you need to first open the MongoDB directory under the Bin directory, and then execute the mongo.exe file, MongoDB Shell is MongoDB with the interactive JavaScript shell, An interactive environment that is used to manipulate and manage MongoDB.
When you enter the MongoDB background, it is linked to the test document (database) by default:
> MONGO
MongoDB Shell version:3.0.6
Connecting To:test
......
Because it's a JavaScript shell, you can run some simple arithmetic operations:
> 2 + 2
4
>
The DB command is used to view documents (databases) for the current operation:
> DB
Test
>
Insert some simple records and look for it:
> Db.runoob.insert ({x:10})
Writeresult ({"ninserted": 1})
> Db.runoob.find ()
{"_id": ObjectId ("5604FF74A274A611B0C990AA"), "X": 10}
>
The first command inserts the number 10 into the X field of the Runoob collection.