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)
SQL VS NoSQL
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
- mongodb documents are json-like documents.
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.collectionName.insert()
> db.bloodDonate.insert({name: 'Go Go', age: 26, blood: 'B'})
collection name > bloodDonate
document > {name: ‘Go Go’, age: 26, blood: ‘B’}
Read documents
db.collectionName.find()
> 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.collectionName.insertMany([])
db.bloodDonate.insertMany([{name: 'John', age: 23, blood: 'O'},{name: 'Micky', age: 30, blood: 'A'}])
Update a document
db.collectionName.updateOne()
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.