Thursday, December 8, 2011

Getting started with MongoDB

First download the MongoDB binaries from the following site - http://www.mongodb.org/downloads and unzip the downloaded binaries to a folder of your choice. Now you have to create a folder where MongoDB can store the data. This won't be created automatically.

Execute the following command in your shell:

C:\> mkdir \data

C:\> mkdir \data\db

At the last step, lets run MongoDB. Navigate to your MongoDB folder and execute the mongod.exe:

C:\> cd \my_mongo_dir\bin

C:\my_mongo_dir\bin>mongod

Now we are ready to start. If you want to open the shell admin console, use the following command:

C:\my_mongo_dir\bin>mongo

You can also use the web-based admin console - http://localhost:28017/

A detailed guide can be find on the following site -http://www.mongodb.org/display/DOCS/Quickstart+Windows

Setting up our database

For this example we will work on a database, which stores authors and their books. To reduce complexity we use a simple console application, but you can use everything learned also in ASP.NET. Let us set up our database and our collection.
If you now not have, start the mongo.exe from the shell:

C:\my_mongo_dir\bin>mongo

To get familiar with the commands you can use, type in the following:

> help

You will see a list with the server-wide commands. For now we will just create a new database:

> use tutorial

If the database exists you will be connected to it. If not, a new database will be created.
To see more database-specific command use the following command:

> db.help()

The last step in setting up our database is to create a collection:

> db.createCollection(books)

 

Flickr Tags: ,,

No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

#Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc

 #Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc Linux is an open-source operating system that is loved by millio...