The document-oriented database impresses with its performance and high horizontal scalability

What is MongoDB? MongoDB is a database based on a non-relational document model. Thus, as a so-called NoSQL database (NoSQL = Not-only-SQL), it differs fundamentally from conventional relational databases such as Oracle, MySQL or the Microsoft SQL Server. The name MongoDB is derived from the English word “humongous”, which roughly means “gigantic”. MongoDB was released in 2009 by founder and developer Eliot Horowitz, who stepped down as Chief Technology Officer and from the Board of Directors of MongoDB Inc. in 2020, but is still active as a technical consultant.
You can find a special video with the caption “connection of database systems” on this topic in our tutorial stream.

MongoDB Icon

1. Database use in the industrial environment

The conceptual differences of the document-oriented NoSQL database MongoDB to conventional SQL databases can be explained in the following example.

In a sales office for plastic parts, a relational database is used for customer management, which stores the customer data there, for example, as in an Excel table consisting of rows and columns. Let’s first look at a small part of this system, the contact information for the customers. It could start with a simple table that contains one row for each customer. This row has a unique customer ID number, a first and last name, email address, phone number and company address.

Now what if we might want to add a second phone number for a customer?

For a work number and a mobile number or even an emergency contact number, we could simply add more columns. The same problem could arise with multiple addresses, for example if a client wants a sample sent to their home office. Also previous addresses or information for a preferred special colour for the plastic parts could be information you might still need. You now simply add more columns for all the customer’s contact information. Eventually you will end up with a bloated, mostly empty, inefficient table as many fields are unused for many other customers.

Database use in an industrial environment with MongoDB

Instead, of course, new spreadsheets could be created in our Excel model if additional data is needed. So here a new separate sheet for telephone numbers, which contains only one telephone number in each row, which refers to the customer ID and is marked with a label like “Private”, “Work” or “Mobile”. Another sheet can be created in this way for addresses and so on.

One would create a multitude of sheets just to look at a single customer and here no thought has even been given to order history or invoice filing. You can guess how quickly working in this rigid schema can get out of control. However, this is how developers work with data in these relational, table-based databases in real applications.

MongoDB: Data in a relational database



1.1 Data in a relational database

The data for a single thing, like a customer, is often spread over dozens of tables and sheets. This significantly increases the complexity of the application and leads to some disadvantages.

Disadvantages of relational databases:

  1. Complexity
    For users who maintain the application, it is difficult to understand the complex and multi-layered structures.
  2. Adding new features
    Adding features is more difficult because, for example, with cross-references there are more tables and sheets to consider.
  3. Retrieve data
    Retrieving data from so many places is inefficient and applications need complex programming codes to deal with it.

Imagine if we transposed this example into the real world and sales representatives had to retrieve names from one file folder, phone numbers from another and addresses from a third folder. You can imagine how complicated, error-prone and slow that would be.

What question do you have about MongoDB?




1.2 How does MongoDB solve the problem?

MongoDB now follows a completely different “schema-free” approach. Data is stored in so-called “documents”.

Just like physical customer files in a hanging file, a document can contain two addresses, three phone numbers and other information, such as an individual training video. It can be stored right next to another customer document that contains only a phone number, an address and no orders yet. These documents are not limited to having the same number of column documents or data fields.

MongoDB data is stored in so-called documents

MongoDB groups several documents into “collections”, of which the database can contain several.

IT can process the data structured in this way more efficiently and, of course, these documents are also much easier for people to read. This type of data storage is incredibly beneficial for developers, as they no longer have to adapt their applications to the requirements of the database. With MongoDB, applications can store data in a natural and convenient way. This also means that adding new data is possible without worrying that a simple change could cause database records to become unreadable.

MongoDB combines several documents in collections



1.3 Differences to traditional databases

In addition to the document model, MongoDB is fundamentally different from traditional databases because its functionality allows MongoDB to coordinate multiple servers to store data.

This makes MongoDB a distributed database and enables it to provide the fault tolerance, scalability as well as data availability features that developers would otherwise have to create themselves and can thus save risks and labour.

  1. Fault tolerance
    To ensure fault tolerance in the work, redundant copies of the same data are kept on different servers. A failure of a single server does not affect the application.
  2. Scalability
    MongoDB scales seamlessly to multiple servers to store and process data. So data volume and performance requirements increase. You can simply add more servers instead of upgrading expensive mainframes. This is also ideal for cloud environments where the load is distributed across many computers.
  3. Data availability
    Data is available locally near users around the world for quick access.

The combination of the MongoDB document model and the distributed system components gives MongoDB an advantage over relational databases.

In addition, the “Mongo” company also provides management tools that allow database operators to oversee the configuration, monitoring, backup, recovery and updating of MongoDB clusters. This is critical to make MongoDB suitable for the most demanding use cases and for organisations with stringent SLA (Service Level Agreement) and operational requirements.




2. MongoDB in the cloud and as a service

MongoDB was developed for the cloud and has been widely used there for some time.

However, more and more users are also interested in creating their applications with components that are offered as a “service”. To meet this need, “MongoDB Atlas” has been released as a service offering. Atlas allows users to use MongoDB as a service without having to worry about managing the database. MongoDB Atlas is available on the leading cloud platforms AWS (amazon web services), Microsoft Azure and the Google Cloud Platform. This provides the flexibility to choose a public cloud provider without vendor lock-in and without having to rewrite code. These innovations are driving more and more companies to incorporate the MongoDB platform.




3. How do I install MongoDB on Windows 10?

In this tutorial, we will cover the installation and basic configuration of MongoDB so that even a beginner without background knowledge can install the database on Windows 10 with this step-by-step guide.

3.1 Download

Please open your internet browser and go to the page “www.mongodb.com“.

Click on the green “Try Free” button at the top right.

On the following page, select “On-premises” and then “MongoDB Community Server“.

The current database version is now displayed on the right-hand side of the screen and you can click on the green download button with the preset values.

3.2 Unpacking and basic installation

Open the downloaded file with a double click. After a short system check, you can start the installation by clicking on “Next“.

In the following window, please tick the box to accept the licence agreement and then click on “Next” again.

The easiest way is to install all programme features: Click on the preselected field “Complete“.

We accept the following information of the “Service Configuration” and click on “Next >” again.

We can also leave the additional installation of MongoDB Compass (a useful graphical user interface) selected and click on “Next” again.

With a final click on “Install“, the installation is now carried out. If further windows of your Windows appear asking you to “Allow changes“, please confirm with “Yes“.

After a short period of time, you can finish the installation by clicking on “Finish“. MongoDB Compass may start automatically. Click through any information windows that may appear and exit MongoDB Compass, as we will not discuss Compass further here and will only deal with the basic database installations in this tutorial.

3.3 User-friendliness

In order to be able to use MongoDB in a user-friendly way, only a few small adjustments are now necessary in Windows before the first start.

Open the file manager “Explorer” under Windows. Click on “This PC” and then double-click your “C: drive“, then double-click on “Programs”, then on “MongoDB“, then on “Server”, then on the version number that appears and finally on “bin”. Here we now need this file path. Above the file display, the window now shows something like “> This PC > Windows (C) > Programs > MongoDB > Server > 4.4 > bin“. Right-click here on “bin” and select “Copy address” to copy the file path to the clipboard.

Now type “var” in the search field of the Windows foot bar and the suggestion “Edit system environment variables” from the control panel should appear. Select this with a mouse click. In the system properties that now appear under the tab “Advanced“, click on the button “Environment variables” at the bottom. In the lower section “System Variables“, double-click on Path. A window “Edit Environment Variable” appears. Here click on “New” and copy the path of the MongoDB installation from the clipboard using CTRL-V. Now confirm the open windows 3 x with “OK” and close them. Now our MongoDB calls and commands are comfortably accessible from all directories.

The last thing we have to do is create the default database directory for MongoDB. Again we go to the search field in the Windows footer to open the command prompt again with “cmd“. In the command prompt we now create the default MongoDB directory with “md c:\data\db“. If no error message appears, we have completed the installation and can subsequently start and test the installed MongoDB in the command prompt.

3.4 Start and test MongoDB

Now we start the database with the command “mongo“. With the command “show dbs“, the three preset databases admin, config and local should now be displayed. To check the functionality, we can now create our own database with the name “NeueDB” using the command “use NeueDB“.

Here we now insert a first data record: The command “db.items.insert ({name: “name”})” creates a first data entry. With the command “db.items.find()” we can check whether the data set with ObjectID is now available. With the command “show dbs“, which is executed again, MongoDB should now show us not only the three standard databases but also the “NewDB” we have just created.

How to implement your digitization strategy with MongoDB – we will be happy to help you!




4. Summary

The NoSQL database MongoDB was developed as an open source project by the community and is now also used extensively in the industrial environment.

However, MongoDB’s pay-as-you-go model, which also exists, is widely used here, as business-critical applications can rarely do without a fully managed failover and complex recovery options. But the community server version available free of charge at www.mongodb.com is an excellent way to enter the NoSQL world with this database.

Further information

MongoDB
An important feature of MongoDB is the high availability of the data through simple replication to multiple servers.
Read here how the OPC Router with the MongoDB Plug-in can access the data of the NoSQL database in read and write mode and supports the handling of replication.
Telegram Bot

A Telegram Bot is a good way to deliver information from almost every conceivable area whenever you need it.
We point out precisely this special mode of operation in an article in our Knowledge Base “Technology” and also provide instructions on how to create a Telegram Bot yourself.

OPC UA

OPC UA – What is it actually?
OPC UA standardises access to devices, machines and other systems in Industrie 4.0 and thus enables manufacturer-independent data exchange. You can find an overview of the terms and functionality of the most important communication protocol for Industry 4.0 and the IoT in our Knowledge Base.

Further interesting articles on the topics of Industry 4.0, cloud, technology, alerting and practical application examples as well as case studies can be found in our Knowledge Base.

Data connection MongoDB via OPC Router Plug-in

With our MongoDB Plug-in you can connect the OPC Router to a MongoDB database.