Go to Downloads - MongoDB.
Find the Current Stable Release of the Community Server, and select the latest 64-bit / 32-bit version in the Windows column. Download, then run the MSI installer.
MongoDB is typically installed in C:\Program Files\MongoDB. Search for Environment Variables on the desktop and add the MongoDB binaries path to the PATH variable. For example, you might find the binaries at C:\Program Files\MongoDB\Server\3.4\bin on your machine.
Create MongoDB data and log directories in the data disk (such as drive F:) you created in the preceding steps. From Start, select Command Promptto open a command prompt window. Type:
- C:\> F:
-
- F:\> mkdir \MongoData
-
- F:\> mkdir \MongoLogs
To run the database move to the C:\Program Files\MongoDB\Server\3.4\bin path, run:
C:\Program Files\MongoDB\Server\3.4\bin> mongod --dbpath F:\MongoData\ --logpath F:\MongoLogs\mongolog.log
All log messages are directed to the F:\MongoLogs\mongolog.log file as mongod.exe server starts and preallocates journal files. It may take several minutes for MongoDB to preallocate the journal files and start listening for connections. The command prompt stays focused on this task while your MongoDB instance is running.
To start the MongoDB administrative shell, open another command window from Start and type the following commands,
- C:\> cd \my_mongo_dir\bin
-
- C:\my_mongo_dir\bin> mongo
-
- >db
-
- test
-
- > db.foo.insert( { a : 1 } )
-
- > db.foo.find()
-
- { _id : ..., a : 1 }
-
- > show dbs
-
- ...
-
- > show collections
-
- ...
-
- > help
The database is created by the insert.
Alternatively, you can install exe as a service:
- C:\> mongod --dbpath F:\MongoData\ --logpath F:\MongoLogs\mongolog.log --logappend --install
A service is installed named MongoDB with a description of "Mongo DB". The --logpath option must be used to specify a log file, since the running service does not have a command window to display output. The --logappend option specifies that a restart of the service causes output to append to the existing log file. The --dbpath option specifies the location of the data directory. For more service-related command-line options, see Service-related command-line options.
To start the service, run this command:
C:\> net start MongoDB
Now MongoDB is installed and running.
Happy coding.