Skip to content

MongoDB Basics for DBAs

MongoDB is a popular, open-source NoSQL database that is known for its scalability and high performance. It uses a document-oriented data model, which means that data is stored in semi-structured format, such as JSON or BSON, rather than in tables as in traditional relational databases. This allows for more flexible and dynamic data structures, making MongoDB a great choice for applications that require real-time access to large amounts of data.

MongoDB is often used in big data and real-time web applications, as well as in content management systems, mobile apps, and IoT applications. It is also well-suited for use cases where the data structure is likely to change over time, as it allows for easy additions, deletions, and modifications to data without the need to update the entire schema.

 

MongoDB Server Processes:

One of the key server processes in MongoDB is the MongoDB daemon, also known as mongod. This process is responsible for managing the storage and retrieval of data, as well as for handling client connections. It uses a memory-mapped file to store data, which allows for efficient storage and retrieval of large amounts of data.

Another important server process in MongoDB is the MongoDB config server, also known as mongos. This process acts as a routing service for client connections, and is responsible for managing the distribution of data across a sharded cluster. It also maintains metadata about the cluster, such as the location of data and the status of different nodes.

MongoDB Replicas:

Additionally, MongoDB uses replica sets to ensure high availability and data redundancy. A replica set is a group of mongod processes that maintain the same data set. One of the mongod instances in a replica set is designated as the primary, and the others are designated as secondaries. The primary instance handles all write operations, while the secondaries keep a copy of the data and can be used for read operations.

 

Some more additional details on MongoDB:

Scaling: MongoDB is designed for horizontal scaling, which means that it can easily handle large amounts of data by adding more machines to the cluster. This is achieved through sharding, which is the process of distributing data across multiple machines. Sharding allows for better performance and scalability, as it allows for more resources to be added as the data set grows.

Indexing: MongoDB supports rich and flexible indexing options, including single-field, compound, and text indexes. Indexes can also be created on any field in a document, and are stored in memory for faster access. This allows for efficient query performance and full-text search capabilities.

Query Language: MongoDB uses a query language called MongoDB Query Language (MQL), which is similar to SQL. MQL is used to query and manipulate data in MongoDB, and supports a wide range of query operations, including filtering, sorting, and projection.

Data Modeling: MongoDB’s document-oriented data model allows for flexible data modeling, as it does not require a fixed schema. This allows for easy additions, deletions, and modifications to data without the need to update the entire schema. MongoDB also supports rich data types, including arrays and sub-documents, which can be used to model complex data relationships.

Security: MongoDB provides several built-in security features such as Role-Based Access Control (RBAC) and field-level encryption. It also supports various authentication mechanisms, including Kerberos and LDAP. Additionally, MongoDB supports secure communication over both native and SSL transports, and also support for client-side and server-side encryption.

Backup and Recovery: MongoDB provides a feature called MongoDB Cloud Manager, which is a cloud-based management platform that provides automated backup and recovery capabilities, as well as monitoring and performance tuning. Additionally, MongoDB also provides a feature called MongoDB Ops Manager, which is a software-based management platform that provides automated backup and recovery capabilities, as well as monitoring and performance tuning.

Community and Support: MongoDB has a large and active community, which provides a wealth of resources such as tutorials, documentation, and sample code. MongoDB also offers professional support and consulting services, as well as a certification program for MongoDB professionals.

 

What do mongodb administrators do?

MongoDB administrators are responsible for the installation, configuration, and maintenance of MongoDB databases. They are responsible for ensuring that the databases are running efficiently and effectively, and that they meet the needs of the organization. Some of the specific tasks that MongoDB administrators may perform include:

  • Installing and configuring MongoDB on servers
  • Configuring and maintaining MongoDB clusters
  • Setting up and managing MongoDB replica sets for high availability
  • Configuring and managing MongoDB sharding for horizontal scalability
  • Creating and maintaining indexes for efficient query performance
  • Monitoring and tuning MongoDB performance
  • Managing MongoDB backup and recovery
  • Managing MongoDB users and roles for security
  • Troubleshooting and resolving MongoDB issues
  • Upgrading MongoDB to new versions
  • Integration with other systems
  • Automating MongoDB administrative tasks
  • Maintaining and securing MongoDB environment
  • Keeping an eye on the capacity planning
  • Overall monitoring of the MongoDB environment

MongoDB administrators typically work closely with developers, data analysts, and other IT staff to ensure that the MongoDB databases meet the needs of the organization. They also need to stay up to date with new releases, features and best practices in MongoDB. They may also be responsible for ensuring compliance with data privacy regulations and ensuring that the MongoDB environment is secure.

 

High-level steps to install standalone MongoDB:

Here are the detailed steps for installing MongoDB on a Linux operating system:

Download the MongoDB package from the official website. You can download the package in the form of a .tgz or .deb file.

Extract the package to the directory where MongoDB will be installed.

tar -zxvf mongodb-linux-x86_64-<version>.tgz

Create a data directory for MongoDB to store its data files. It is recommended to create a data directory in a different location than the MongoDB installation directory,

mkdir -p /data/db

Start the MongoDB server by running the mongod command, specifying the data directory and any other necessary options.
bash

./mongod --dbpath /data/db

Verify that the MongoDB server is running by connecting to it using the mongo shell.

./mongo

(Optional) Set up MongoDB as a service by creating a systemd service file

sudo nano /etc/systemd/system/mongodb.service

 

[Unit]
Description=MongoDB Database
After=network.target

[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

 

Reload the systemd daemon and start the MongoDB service

sudo systemctl daemon-reload
sudo systemctl start mongodb

(Optional) Enable the MongoDB service to start automatically at boot time
bash

sudo systemctl enable mongodb

Verify that the MongoDB service is running by checking the status
lua

sudo systemctl status mongodb

It’s important to note that these steps are for a Linux operating system and may vary depending on the operating system you are using. It’s always recommended to read the official MongoDB documentation for the version you are using to get detailed instructions.

It’s also important to note that these steps are for a standalone MongoDB installation, if you want to set up a sharded cluster or a replica set, additional steps are needed.

 

Brijesh Gogia
Leave a Reply