DBPedias

All your database knowledge are belong to you

MongoDB

MongoDB Quickstart Windows

Contents

Download

The easiest (and recommended) way to install MongoDB is to use the pre-built binaries.

32-bit binaries

Download and extract the 32-bit .zip. The "Production" build is recommended.

64-bit binaries

Download and extract the 64-bit .zip.

Note: 64-bit is recommended, although you must have a 64-bit version of Windows to run that version.

Unzip

Unzip the downloaded binary package to the location of your choice. You may want to rename mongo-xxxxxxx to just "mongo" for convenience.

Create a data directory

By default MongoDB will store data in C:\data\db, but it won't automatically create that folder, so we do so here:

C:\> mkdir \data 
C:\> mkdir \data\db 

Or you can do this from the Windows Explorer, of course.

Run and connect to the server

The important binaries for a first run are:

  • mongod.exe - the database server
  • mongo.exe - the administrative shell

To run the database, click mongod.exe in Explorer, or run it from a CMD window.

C:\> cd \my_mongo_dir\bin 
C:\my_mongo_dir\bin > mongod 

Note: It is also possible to run the server as a Windows service. But we can do that later.

Now, start the administrative shell, either by double-clicking mongo.exe in Explorer, or from the CMD prompt. By default mongo.exe connects to a mongod server running on localhost and uses the database named test. Run mongo --help to see other options.

C:\> cd \my_mongo_dir\bin 
C:\my_mongo_dir\bin> mongo 
> // the mongo shell is a javascript shell connected to the db 
> 3+3 
6 
> db 
test 
> // the first write will create the db: 
> db.foo.insert( { a : 1 } ) 
> db.foo.find() 
{ _id : ..., a : 1 } 

Congratulations, you've just saved and retrieved your first document with MongoDB!


Taken from the MongoDB Quickstart Windows documentation. Originally published under a Creative Commons license.