MongoDB is an open source database created by 10gen . It has an enterprise edition which has some good features which are not available in the free versions. This database is designed to process a huge amount of data located on different servers which can't be handled by a traditional database system. Since the data is growing day by day there is a strong need for scalable databases. Here is where NoSql databases come into play. NoSql databases are highly scalable when compared to SQL.
You can check the advantages of NoSql Databases Here
Getting Started With MongoDB:
Step 1: MongoDB is available for windows ,and various Linux distros. You can download the package here. MongoDB Download
Step 2: Here I am going to explain the windows installation of MangoDB. Once you downloaded the momgoDB package, unzip it to C drive. Move the default folder which contains the version number to mongoDB using the following command in windows command prom. you can also do it manually by renaming the folder to mongoDB
move C:mongodb-win32-5-* C:mongodb
Step 3: Create a folder named data and inside the data folder creates another folder called DB eg: c://datadb.
Step 4: MongoDB can be installed using the following command in cmd and if it shows the message "waiting for connections" after executing the code, it means that process has started successfully.
C:mongodbbinmongod.exe
Step 5:Open a new cmd window and type in the following command to open the mogoDb shell. Once the command is successfully executed, the command shell for mongoDB will be opened.
C:mongodbbinmongo.exe
MongoDB Basic Operations:
1.Database creation: You need not define a structure for mongoDB , everything will be processed created on the fly. you can create a database using the command "use db_name" .The database will not be displayed until some document is inserted into the database. In mongoDB tables are called "collections." Use the following commands to create a database and collection in mongoDB.
db -->Lists the current database in use use database_name -->database will be created with the given name. show dbs -->lists all the databases
Company_info = ({name : "cloudtechies" , type : "blog" } )
Technology_base = ({ base : "cloud technology" , Type: "tutorials" } )
3.Inserting Documents into collections: Use the following commands to insert the documents into a collection.
db.orginfo.insert(company_info)
db.orginfo.insert(technology_base)
show collections
4. Using For Loop For Inserting Documents: You can insert documents through various iterations using a for loop. Use the following syntax for inserting documents using for loop.
for ( var i = 0 ; var i <=10 ; i ++)
db.demofor.insert({ x : i-- , j : i } )
5.Retrieving Documents From Collections: find() function is used to list all the documents in a collection. By default, it only displays first 20 results.For next 20 results you just have to type "it".
Syntax: db.collection_name.find()
db.orginfo.find()
it
6. Using Cursors For Selecting a specific file: By assigning the find results to a variable you can find the specific document through the array index. "Printjson" function prints the selected files.
var list= db.demofor.find()
printjson (list[4])