Empowering the younger Generation

Empowering the younger Generation


Monday, February 19, 2018

MongoDB

MongoDB
 

1.What is the database?

* A Database is an organized collection of data. It is the collection of schemas, tables, queries, reports, views, and other objects. The data are typically organized to model aspects of reality in a way that supports processes requiring information, such as modeling the availability of rooms in hotels in a way that supports finding a hotel with vacancies.

* Database is a physical container for collections. Each database gets its own set of files on the file system. A single MongoDB server typically has multiple databases.




Why use the database?

* To organize and preserve data
* To facilitate analysis and modeling
* To gain insights into the relationship in your data
* To help turn data into information
* To explore data using exploratory techniques
* To support the organization 
                              1.What is MongoDB?


* MongoDB is a free and open source cross-platform document-oriented database program.classified as an NOSQL database program.MongoDB uses JSON -like documents with schemas. MongoDB is developed by MongoDB inc.and is free and open-source.

* MongoDB is an open-source document database and leading NoSQL database. MongoDB is written in C++.

MongoDB is a cross-platform, document-oriented database that provides, high performance, high availability, and easy scalability. MongoDB works on the concept of collection and document.




2.How to work MongoDB


3.WHY USE THE COLLECTION IN MONGODB?

* Collection is a group of MongoDB documents. It is the equivalent of an RDBMS table. A collection exists within a single database. Collections do not enforce a schema. Documents within a collection can have different fields. Typically, all documents in a collection are of similar or related purpose.



4.WHY USE THE DOCUMENT IN MONGODB?

* A document is a set of key-value pairs. Documents have a dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection's documents may hold different types of data.


The following table shows the relationship of RDBMS terminology with MongoDB--        
  



 -- Sample document here in MongoDB--
{
   _id: ObjectId(7df78ad8902c)
   title: 'MongoDB Overview', 
   description: 'MongoDB is no sql database',
   by: 'tutorials point',
   url: 'http://www.tutorialspoint.com',
   tags: ['mongodb', 'database', 'NoSQL'],
   likes: 100, 
   comments: [ 
      {
         user:'user1',
         message: 'My first comment',
         dateCreated: new Date(2011,1,20,2,15),
         like: 0 
      },
      {
         user:'user2',
         message: 'My second comments',
         dateCreated: new Date(2011,1,25,7,45),
         like: 5
      }
   ]
}

     How to use mongoDB commands

 1.create database

* use DATABASE_NAME
-Example-
* If you want to create a database with name <UKI_STUDENTS>, then use DATABASE statement would be as follows

>use uki_students
     switched to db uki_students
* To check your currently selected database, use the command DB
s
>db
   uki_students

>show dbs
     uki_students  0.23012GB

 2.Drop database

* db.dropDatabase()
-Example-

* MongoDB db.dropDatabase() command is used to drop a existing database.

>db.dropDatabase()

* If you want to delete new database <uki_students>, then dropDatabase() command would be as follows

>use uki_students
switched to uki_students
db.dropDatabase() 
{ "dropped" : "uki_students", "ok" : 1 }

3.createCollection

*db.createCollection(name, age)
-Example-

>use test
 switched to db test 
db.createCollection("mycollection") 
{ "ok" : 1 }



 Next i will meet you in my next blog....

                          .....Thank you.....!