window platform installation MongoDB

window platform installation MongoDB



MongoDB Download

MongoDB provides a 32-bit and 64-bit systems pre-compiled binary packages you can download and install from the official website of MongoDB, MongoDB precompiled binary packages Download: https://www.mongodb.com/try

Note: After MongoDB2.2 version no longer supports Windows XP system.

  • MongoDB for Windows 64-bit for 64-bit Windows Server 2008 R2, Windows 7, and the latest version of the Window System.
  • MongoDB for Windows 32-bit for 32-bit Window systems and the latest Windows Vista.On 32-bit systems MongoDB databases up to 2GB.
  • MongoDB for Windows 64-bit Legacy for 64-bit Windows Vista, Windows Server 2003, and Windows Server 2008.

Depending on your system, download the 32-bit or 64-bit .msi file, double-click the downloaded file and follow the prompts to install the operation.

During installation, you can click on the "Custom (Custom)" button to set your installation directory.

Create a data directory

In db directory MongoDB will store data directory. But this will not take the initiative to create the data directory, we need to create it after installation is complete. Note that the data directory should be placed in the root directory ((eg: C: \ or D: \, etc.).

In this tutorial, we have the C: drive is installed mongodb, now let's create a data directory and then create db directory 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 of the Explorer, and not necessarily through the command line.



Under the command line to run MongoDB server

To run MongoDB server from a command prompt, you must perform mongod.exe files from the bin directory MongoDB directory.

mongod.exe --dbpath c:\data\db

If successful, it will output the following information:

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
……


The MongoDB server as a Windows service

Please note that you must have administrative rights to run the following command. Execute the following command MongoDB server 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 shows the parameters mongodb started Explanation:

parameter description
--bind_ip Binding IP services, if binding 127.0.0.1, you can only access the machine, do not specify a default for all local IP
--logpath Given MongoDB log file, note that the specified file is not a directory
--logappend Use additional way to write the log
--dbpath Specify the database path
--port Specifies the service port number, the default port 27017
--serviceName Specify the service name
--serviceDisplayName Specifies the service name, service execution when there are multiple mongodb.
--install Designated as a Windows service.


MongoDB Manage Shell

If you need to enter the MongoDB management background, you need to open the bin directory mongodb installation directory, and then execute mongo.exe document, MongoDB Shell is MongoDB comes with an interactive Javascript shell, used to MongoDB interact and management type environment.

When you enter mongoDB the background, it will default to link to test document (database):

> mongo
MongoDB shell version: 3.0.6
connecting to: test
……

Since it is a JavaScript shell, you can run some simple arithmetic:

> 2 + 2
4
>

db command is used to view a document of the current operation (database):

> db
test
>

Insert some simple record and find it:

> db.w3resource.insert({x:10})
WriteResult({ "nInserted" : 1 })
> db.w3resource.find()
{ "_id" : ObjectId("5604ff74a274a611b0c990aa"), "x" : 10 }
>

The first command is inserted into a digital x 10 field w3resource collection.