Databases 7 min read

MongoDB Fundamentals: Document Model, BSON, and CentOS 7 Installation

This article introduces MongoDB as an open-source document database, explains NoSQL categories, details MongoDB's data model (fields, documents, collections, databases) with relational database analogies, and provides step-by-step installation instructions for MongoDB 7.0 on CentOS 7 via yum and manual RPM.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
MongoDB Fundamentals: Document Model, BSON, and CentOS 7 Installation

Introduction to NoSQL and MongoDB

NoSQL (Not Only SQL) refers to non-relational databases that have grown beyond traditional SQL capabilities. Unlike relational databases, NoSQL stores data in non-tabular forms and offers advantages such as flexible data models, horizontal scalability for large-scale storage, fast retrieval without JOINs, and developer-friendly interfaces.

NoSQL Database Types

NoSQL databases are primarily categorized into four types:

Document databases

Key-value databases

Wide-column databases

Graph databases

MongoDB Overview

MongoDB is an open-source, distributed document database that provides document-oriented storage. It is considered the NoSQL database most similar to relational databases, offering a gentle learning curve for traditional database users. Key advantages include flexible schema, horizontal scaling, high performance, and rich query capabilities.

Core Concepts: Fields, Documents, Collections, Databases

MongoDB's storage structure consists of:

Field : A key-value pair (name-value), similar to a column in relational databases. A document contains zero or more fields.

Document : The basic data unit, a record in a collection, stored in BSON (Binary JSON) format which extends JSON with additional data types.

Collection : A group of documents, analogous to a table. Documents within a collection can have different fields.

Database : A container for multiple collections, similar to a relational database. A MongoDB server typically hosts multiple databases, each with its own files on the filesystem.

Comparison with Relational Database Concepts

The following diagram illustrates the mapping between MongoDB and relational database terminology:

MongoDB vs RDBMS concept comparison
MongoDB vs RDBMS concept comparison

BSON Document Structure

MongoDB records are BSON documents composed of key-value pairs. Field keys are strings; values can include nested documents, arrays, and other BSON types. The example below shows a sample document from the official documentation:

BSON document example
BSON document example

Installing MongoDB 7.0 on CentOS 7

Method 1: YUM Repository Installation

Create a repository file: vi /etc/yum.repos.d/mongodb-org-7.0.repo Add the following configuration:

[Mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc

Then install:

sudo yum install -y mongodb-org

Method 2: Manual RPM Installation

Download the required RPM packages from the official MongoDB download center (select version 7.0, platform Red Hat/CentOS 7, package type RPM). The download page appears as follows:

MongoDB download page
MongoDB download page

Also download the MongoDB Shell (mongosh) package:

MongoDB Shell download page
MongoDB Shell download page

Upload the RPM files to a directory (e.g., /opt/mongodb) and install with:

rpm -ivh mongodb-org-server-7.0.2-1.el7.x86_64.rpm
rpm -ivh mongodb-org-mongos-7.0.2-1.el7.x86_64.rpm
rpm -ivh mongodb-mongosh-2.0.2.x86_64.rpm

Verification

Run the MongoDB shell and list databases to confirm successful installation:

mongosh
show dbs

If the command executes and displays existing databases, the installation is successful.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Document DatabaseInstallationMongoDBNoSQLBSONYUMCentOS 7Database Concepts
Full-Stack Internet Architecture
Written by

Full-Stack Internet Architecture

Introducing full-stack Internet architecture technologies centered on Java

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.