Evolution of a Node.js API, Zoe.js — MongoDB

Adams Academy
2 min readJul 17, 2020

--

MongoDB is a document oriented database. Relational databases use tables and rows to store data, while MongoDB uses collections and JSON-like (BSON) documents. Let's see an example document of a Person:

{
_id: ObjectId(5ef9ad76d0b5e4ad986c1552),
email: "theadamsacademy@gmail.com",
name: "Adam",
addresses: [
{
...
},
{
...
}
]
}

_id is a reserved field name, it is the primary key, therefore it must be unique and it is immutable. Besides the _id field you can have any other key-value pairs and a value may include other documents, arrays, and arrays of documents.

MongoDB is a not a silver bullet, you can easily find yourself at a place where you have god objects which contain everything.

Databases can have schemas but it’s optional, so there is no need of pre-defined schema in Mongo. MongoDB is really easy to scale horizontally through multiple servers. It’s also fault tolerant, it can keep redundant copies of the databases, a single server failure doesn’t effect the application.

Basic commands

Let’s see the most basic commands in the mongo shell which is an interactive interface to MongoDB.

  • use <database> is for switching database
  • db is for fetching the current database
  • db.<collection>.insertOne(...) is for inserting one document into the collection
  • db.<collection>.find({}) is for fetching all the documents from the collection

Atlas

We will use MongoDB Atlas for storing data.

MongoDB Atlas is a cloud database. It handles both database management, scaling and deployment on various cloud service providers AWS, Azure, Google Cloud.

Article Series

This article (Chapter 5) is part of the Zoe.js article series. Below you can find the Next chapter and all the available Chapters.

--

--

Adams Academy

Adams Academy helps you to cut through the noise and understand programming languages, web development with simple programming tutorials.