Install mongo db
Before we start use of mongo db we need to know, what is mongo db?
MongoDB is an open-source document database and non sql database that provides high performance, high availability, and automatic scaling.It stores data in flexible, JSON-like format. MongoDB is written in C++. MongoDB is developed by MongoDB Inc.
To install MongoDB on Windows operating system, first download the latest release of MongoDB from https://www.mongodb.com/download-center. Make sure you get correct version of MongoDB depending upon your Windows operating system version.If you have 32 bit version windows operating system download mongo db for 32 bit version or if you have 64 bit then download for 64 bit.
Next create a folder in C: drive with name mongodb.Install the mongo db to this folder.Now create another folder in C: drive with name “data” and also create another folder inside this with name db.
Now open the command prompt ,type the below command.
c:\mongodb\bin\mongod.exe --dbpath c:\data\db
Now wait for connection.If connection is successfully done the open the command prompt in window.Type the below command.
cd.. (press enter) cd.. (press enter) cd mongodb\bin (press enter) mongo.exe (press enter) The oupput MongoDB shell version: 2.4.6 connecting to: test
Now if you want to create new db enter “use your-db-name”.
If you want to see list of db ,type “show dbs”
if you want to drop database,use the following command
>use your-db-name >db.dropDatabase()
if you want to create table(collection) , use the following command
>db.createCollection("collection-name", options)
Here collection is like table of sql database.In collection we can store data.
Here name for table will be string.Here option is optional.Specify options about memory size and indexing.
Create a Capped Collection
Capped collections have maximum size or document counts that prevent them from growing beyond maximum thresholds.
db.createCollection("collection-name", { capped : true, size : 5242880, max : 5000 } )
If you want to delete collection then use the following command.
>db.COLLECTION_NAME.drop()