+1

[DATABASE - MONGO] Introduction to MongoDB

I. Introduction

  • MongoDB is an open source NoSQL database management, designed to store a large scale of data and allows to work with data efficiently. (high performance, high availability and easy scalability)
  • MongoDB is written in C++.
  • It uses collections and documents to store data instead of using tables like traditional relational databases.
  • Data is stored in json format called bson.
  • MongoDB allows users to save nested documents.

1. Database

  • Database is a physical container for collections.
  • A MongoDB server can have multiple databases.

2. Collection

  • A collection is a set of MongoDB documents, it is the equivalent of an RDBMS table.
  • Collections do not enforce a schema which means documents in the same collection can have different fields.
  • Documents in the same collection have the related purpose.

3. Documents

  • Document is a set of key-value pairs.
  • It has flexible schema (they dont need to have the same sets of fields or structure).
  • Documents' common field can hold different data types.

4. Example of document

{
   _id: ObjectId(7df78ad8902c)
   name: 'Vivian', 
   gender: 'female',
   abilities: ['reading', 'speaking', 'eating'],
   friends: [	
      {
         name:'Ann',
         gender: 'female',
      },
      {
         user:'Irene',
         gender: 'female',
      }
   ]
}

5. Comparision of RDBMS and MongoDB structure

RDBMS MongoBD
Database Database
Table Collection
Row Field
Table Join Embedded documents
Primary key default key _id auto-created by MongoDB

II. Installation & setup

image.png

  • Open the msi file when the download is completed and click next button.

image.png

  • Accept the End-USer License and click next.

image.png

  • Click complete.

image.png

  • Copy link of Data Directory and click next.

image.png

  • Click next then install MongoDB and wait for the process to complete.

image.png

image.png

image.png

  • Click finish to complete installation process.

image.png

  • Go to path C:\Program Files\MongoDB\Server\your-version\bin where MongoDB installed and copy this path.

image.png

  • Create an environment variable.

    • open system properties > select environment variables

    image.png

    • choose Path and click Edit

    image.png

    • Click New > Paste the copied path > OK.

    image.png

  • Open C drive and create folder data and its sub folder db then open command prompt and run mongod command. If data is shown, that means the MongoDB run successfully.

image.png


All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí