MongoDB (Introduction and Usage)

  • type of databases
  • what is mongodb
  • start using of mongodb
  • CRUD (Create, Read, Update, Delete)

Type of databases

People use database to store and manage data (information) safety. If your application have user information , and become need store them in safety place. Most people would have heard about MySQL (a popular database software)


There are so many types of database and in this story I am gonna share about SQL and NoSQL as far as I know.

  • SQL is Structure-Query-Language, Relational database and table-based database . Means that in database that have table and data are stored in table. In SQL database structure, database have table and table have rows and columns. Popular SQL database is MySQL.
  • NoSQL is Not-only-Structure-Query-Language and Non-Relational database and document-based database. Data are stored as document. In NoSQL database structure, database have collections and in collections have documents and document has fields. Popular NoSQL database is MongoDB.

These two have own pros and cons. NoSQL is more faster than SQL but SQL is better for complex queries.

MongoDB Docs

If you want to know more, MongoDB documentation is the best. In documentation, there are server, cloud, drivers section.

  • In server section, about mongoDB server.
  • Cloud section is about when you deploy application, local database is needed to change to cloud database.
  • Drivers section is about connection of database with application. If you want to connect with nodeJS with mongodb, there is MongoDB Node Driver.

Installing MongoDB

I succeeded of installing MongoDB following the steps from London App Brewery (How to Download & Install MongoDB)

Start using of MongoDB

  • Open your terminal
  • Run MongoDB server with the command
$ mongod
  • Open the new Tab and use mongoDB client with the command
$ mongo

Now, we are going to starting using the db.

Don’t forget about our MongoDB database structure

Database > Collections > Documents > Fields

Before you start

example document {name: ‘Jone’, age: ‘17’}

  • when you create mongodb collection, no need to predefine

CRUD (Create, Read, Update, Delete)

  • Let’s see databases with the command
$ show dbs

Database Project

I want to record donor’s (name, age, blood type) for Blood Donation Database.

  • Let’s create database [hospital]
> use hospital

Although we don’t have no hospital database, and the command ‘use ’ means that create a new database named hospital and use hospital database.

Create a document

  • Now we gonna create a document in collection [blood-donate]


> db.bloodDonate.insert({name: 'Go Go', age: 26, blood: 'B'})

collection name > bloodDonate

document > {name: ‘Go Go’, age: 26, blood: ‘B’}

Read documents


> db.bloodDonate.find()
{ “_id” : ObjectId(“5faebf45d531fcf007cb666d”), “name” : “Go Go”, “age” : 26, “blood” : “B” }

we will see a document that contains name field, age field and blood field

Create many documents


db.bloodDonate.insertMany([{name: 'John', age: 23, blood: 'O'},{name: 'Micky', age: 30, blood: 'A'}])

Update a document


db.bloodDonate.updateOne({'name': 'Go Go'}, {$set: {"blood" : "AB"}})

find name of ‘Go Go’ and replace the blood type ‘AB’

Delete a document

db.bloodDonate.deleteOne({'blood': 'O'})

find blood type O and delete.




Learning javascript and web-development

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Swarm Fundamentals & How to develop unstoppable dApps on Swarm

Why Software Developers Need To Adopt a Systems Thinker’s Mindset

Several cups in a cupboard

Build Number Masking into your application with MessageBird

Why You Must Experience NoSQL Databases. (MySQL)

Django week 4

Building a Tradable Stock Universe With Alpaca

Redis in Ruby — Chapter 1 — A basic TCP server

Powerful workflows in Slack

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cho Zin Thet

Cho Zin Thet

Learning javascript and web-development

More from Medium

Deploying Flask Web App with docker || docker port forwarding issue in Flask Application || docker…

Node + Express + Knex + PostgreSQL

Which is Most Demanding Web Framework: Laravel, Node.js, and Django

A step by step how to start docker-compose container at boot