Installation of Mongo DB is as simple as copy pasting a folder in your system.
To start with download the Mongo DB installer from Mongo DB download site according to your OS version (32 bit or 64 bit).
Download the zip file (for windows) or tgz file (for linux). Extract the file to a folder (say mongodb-win32-x86_64-2.4.6). Believe me your Mongo DB installation is done. It's that so simple. :)
The default configuration is also that simple. Create a folder at your root directory called /data/db. If you are a windows user create the directory in C:\. (Don't worry if you cannot create the same due to permission issue, we have the custom configuration option, to be discussed in future post).
Now go to the folder where you have extracted Mongo DB installation. Navigate to /bin folder inside that. You will see few exe (or sh) files.
For windows run mongod.exe by double clicking the file (type command ./mongod in linux shell). You will see something like the following image.
It says your Mongo DB instance is started successfully at port 27017. It says other details too; no hurry we will describe each of them later.
From the bin folder double click on another file called mongo.exe (for linux type ./mongo). The mongo shell will open. Here is the place you type various commands, query your database, perform administrator operation etc.
From the above command window it says it is by default connected to a database called test.
Lets insert the first record into your database. Type the following command db.foo.insert({"a":1,"b":2}).
Here db -> keyword,
foo -> collection you are inserting the document
insert -> command to insert
{"a":1,"b":2} -> JSON document
Now lets query whatever we have inserted just now. Type db.foo.find().
You will see the data we have just added with an additional key called "_id". This is an auto generated primary key for each document in Mongo collection. This is actually an ObjectId type (we will cover this also in the future discussion).
That's it. Your first Mongo DB exercise is complete. Simplicity matters.
<< Prev Next >>
To start with download the Mongo DB installer from Mongo DB download site according to your OS version (32 bit or 64 bit).
Download the zip file (for windows) or tgz file (for linux). Extract the file to a folder (say mongodb-win32-x86_64-2.4.6). Believe me your Mongo DB installation is done. It's that so simple. :)
The default configuration is also that simple. Create a folder at your root directory called /data/db. If you are a windows user create the directory in C:\. (Don't worry if you cannot create the same due to permission issue, we have the custom configuration option, to be discussed in future post).
Now go to the folder where you have extracted Mongo DB installation. Navigate to /bin folder inside that. You will see few exe (or sh) files.
For windows run mongod.exe by double clicking the file (type command ./mongod in linux shell). You will see something like the following image.
It says your Mongo DB instance is started successfully at port 27017. It says other details too; no hurry we will describe each of them later.
From the bin folder double click on another file called mongo.exe (for linux type ./mongo). The mongo shell will open. Here is the place you type various commands, query your database, perform administrator operation etc.
From the above command window it says it is by default connected to a database called test.
Lets insert the first record into your database. Type the following command db.foo.insert({"a":1,"b":2}).
Here db -> keyword,
foo -> collection you are inserting the document
insert -> command to insert
{"a":1,"b":2} -> JSON document
Now lets query whatever we have inserted just now. Type db.foo.find().
You will see the data we have just added with an additional key called "_id". This is an auto generated primary key for each document in Mongo collection. This is actually an ObjectId type (we will cover this also in the future discussion).
That's it. Your first Mongo DB exercise is complete. Simplicity matters.
<< Prev Next >>
No comments:
Post a Comment