Getting Started with Database – MongoDB

Getting Started with Database – MongoDB

Data is a collection of distinct information and to store this data, one would require a database. This article is an introduction to MongoDB and to fully understand it, you should have a general knowledge of databases.

A database is an organized collection of structured data, making it easy to access and manage the data stored in it. Looking at a wardrobe or closet as an example, the closet is usually used to store clothes, here the clothes are the data and the closet the database. There are several types of databases, a few of them include;

image.png MongoDB (DB - Database) is a document-oriented NoSQL database used for high volume data storage. Instead of using tables and rows as in the traditional relational databases, it uses collections that contain sets of documents. These documents consist of key-value pairs which are the basic unit of data in MongoDB. Both the collections and documents function as the equivalent of relational database tables and rows.

Some advantages of MongoDB over relational databases

  • Firstly, it is very easy to install and setup MongoDB, find a guide here.
  • It is a schema-less database, meaning there is no pre-defined skeleton or constraints to the data arrangement as your code defines the schema.

A database schema is the skeleton structure that represents the logical view of the database. It defines how the data is organized and how the relations among them are associated.

  • The ability to derive a document-based data model is one of the most attractive advantages of MongoDB because it stores data in the form of JSON – JavaScript Object Notation or BSON (Binary JSON) etc. Thus, storing data in a very rich way and capable of holding arrays and other documents. For example;
    {
    "title": "Test 1",
    "body": "Body 1",
    "author": {
       "id": 5,
       "name": "John Doe",
       "email": "aaa@yahoo.com"
      }
    }
    
  • Mapping of your application objects to the database objects is not needed, there are also no complex joins, etc.

After downloading and setting up MongoDB, there are some commands you can run from the terminal, command prompt, or shell to create, view, update, sort, delete or simply manipulate your database or collections. Find a list of the commands here and get creative with them. You can also check the resources below for further assistance.

Thanks for reading! 😁

image.png

Resources