Introduction to MongoDB: Why MongoDB?

Lokesh Gupta

Before jumping directly into basics of MongoDB, we should try to understand the need to No-SQL database itself. Why the traditional relational databases are loosing the battle with their new competitor like MongoDB. Why they are so popular now-a-days. Why?

Why NoSQL?

Interactive applications have changed dramatically over the last 15 years, and so have the data management needs of those apps. Data is becoming easier to capture and access through third parties such as Facebook, D&B, and others. Personal user information, geo location data, social graphs, user-generated content, machine logging data, and sensor-generated data are just a few examples of the ever-expanding array of data being captured. And the use of the data is rapidly changing the nature of communication, shopping, advertising, entertainment, and relationship management. Apps that don’t leverage it quickly will quickly fall behind.

Developers want a very flexible database that easily accommodates new data types and isn’t disrupted by content structure changes from third-party data providers. Much of the new data is unstructured and semi-structured, so developers also need a database that is capable of efficiently storing it. Unfortunately, the rigidly defined, schema-based approach used by relational databases makes it impossible to quickly incorporate new types of data, and is a poor fit for unstructured and semi-structured data. NoSQL provides a data model that maps better to these needs.

Why MongoDB?

MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling across a configurable set of systems that function as storage nodes.


MongoDB shines because of its ease of use, whether a developer is using it in a large-scale application that spans hundreds or thousands of nodes, or in a single-server application that has no need for scale.

If you remember that in JSON we store the information in key-value pairs like this:

{
   name : "lorem",
   address : "ipsum
}

MongoDB stores all data in documents, which are JSON-style data structures composed of field-and-value pairs. MongoDB stores documents on disk in the BSON serialization format. BSON is a binary representation of JSON documents, though it contains more data types than JSON. These documents can be simple documents as above and can also be complex documents such as below:

{
    id: x,
    name: y,
    other: z,
    multipleArray: [
        {lab1: "A",  lab2: "B", lab3:"C"},
        {lab1: "AB", lab2: "BB", lab3:"CB"},
        {lab1: "AC", lab2: "BC", lab3:"CC"}
    ]
}

Most user-accessible data structures in MongoDB are documents, including:

-> All database records.
-> Query selectors, which define what records to select for read, update, and delete operations.
-> Update definitions, which define what fields to modify during an update.
-> Index specifications, which define what fields to index.
-> Data output by MongoDB for reporting and configuration, such as the output of the server-status and the replica set configuration document.

Please note that there are some limitations of MongoDB as well when comparing to relational databases:

a) It doesn’t support Joins
b) It doesn’t support Transactions

That’s all for this little introductory post. These are hundreds of concepts which we will learn when we start learning MongoDB.

Happy Learning !!

References:

https://www.mongodb.com/nosql-explained/best-nosql-database
https://www.mongodb.com/docs/manual/introduction/

Comments

Subscribe
Notify of
guest
3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial

Dark Mode

Dark Mode