Book Image

MongoDB High Availability

By : Afshin Mehrabani
Book Image

MongoDB High Availability

By: Afshin Mehrabani

Overview of this book

Table of Contents (17 chapters)
MongoDB High Availability
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Utilizing MongoDB components


This section contains a brief description of the MongoDB components, file names, and the main purpose of each of them. We will further discuss each item in detail. The following diagram shows you the four main components of MongoDB:

MongoDB components can mainly be classified into the following categories:

  • Core components

  • Import and export tools

  • Diagnostic tools

  • File storage (GridFS) tools

Each file can be placed into one of the aforementioned categories. The core component files are used to run the MongoDB server and start it. The files are also used to manage the MongoDB server from the command-line interface or manage clustering tasks.

Using import and export tools, developers can create dump files from their database in different formats such as BSON, JSON or CSV and restore them into another database again. Certain tools are used to create or restore BSON files, and some tools are responsible for generating and importing other common formats such as JSON or CSV.

MongoDB has many built-in diagnostic tools to manage and control the currently running server. Finally, we can use GridFS tools to interact with filesystem and GridFS components. In the next section, we will give you more details for each category and the processes inside them.

Understanding the core components

Inside this category, you can find the core processes that are required to start the MongoDB server. The MongoDB engine uses these tools to accept requests from different clients.

The components and executable files in this group are as follows:

  • mongod

  • mongo

  • mongos

Understanding mongod

The mongod component is the primary process that is needed for MongoDB to start the server. It manages requests or queries and handles connections.

The following screenshot is the result of executing mongod from the command-line interface:

The preceding screenshot illustrates the result of running mongod from the command line, that is, you finally have a MongoDB server running on port 27017 and a web interface on port 28017, which is the default port.

Like other MongoDB commands, in order to see the parameters of the mongod process, you can simply run following command:

mongod --help 

Here, you can see the result of running the mongod command with the --help parameter. This is shown in the following screenshot:

Note

To read more about the command and figure out what each parameter does, you can visit the MongoDB documentation page at http://docs.mongodb.org/manual/reference/program/mongod/.

Utilizing mongo

After starting the database server, we need to interact with it to issue a command, run commands, run queries, or get reports. In the MongoDB structure, the mongo file is responsible for this task. This is an interactive JavaScript shell that you can utilize from your command-line environment.

Using this executable file, database administrators and also developers can manage the database server or get available databases and collections.

The following screenshot is the result of running the mongo command:

Fortunately, the mongo component provides internal help so that developers can use it to get more information for each command.

The following screenshot shows you the result of running the help command:

Note

To acquire more information about MongoDB and all its parameters, you can visit the MongoDB documentation page at http://docs.mongodb.org/manual/reference/program/mongo/.

Learning about mongos

The mongos instance is responsible for routing read/write commands to shards in a sharded cluster. In fact, all processes and applications will connect to this instance and run queries, then the mongos instance will route commands to available shards. The applications will not interact with shards directly. To run the mongos instance, we can provide sharded cluster configurations using a config file or command-line parameters.

In further chapters, we will discuss this process in detail.

Note

To gain more knowledge about the mongos command and its parameters, you can visit the MongoDB documentation page at http://docs.mongodb.org/manual/reference/program/mongos/.