DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Observability Architecture: Financial Payments Introduction
  • Top 10 Pillars of Zero Trust Networks
  • A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage
  • VPN Architecture for Internal Networks

Trending

  • Observability Architecture: Financial Payments Introduction
  • Top 10 Pillars of Zero Trust Networks
  • A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage
  • VPN Architecture for Internal Networks
  1. DZone
  2. Data Engineering
  3. Databases
  4. Getting Started With MongoDB

Getting Started With MongoDB

In this brief getting-started tutorial, learn about MongoDB, one of the most powerful NoSQL databases.

Shubham Agarwal user avatar by
Shubham Agarwal
·
May. 03, 18 · Analysis
Like (9)
Save
Tweet
Share
10.37K Views

Join the DZone community and get the full member experience.

Join For Free

Hi, everyone! In this article, I will try to explain what MongoDB is and why to use MongoDB.

What Is MongoDB?

MongoDB is one of the most powerful NoSQL databases. It does not use the usual rows and columns that we are so much used to with relational database management. It is an architecture built on collections and documents.

This database uses a document storage format called BSON, which is a binary style of JSON-style documents.

  • It is a document-oriented NoSQL database.
  • It is a schema-free database and based on a binary JSON format called BSON.
  • It stores the data in the collection, which is simply a group of documents.
  • It has an auto-sharding feature in order to scale horizontally.

Let’s explore and see how it is different from an RDBMS:

RDBMS MongoDB
Database Database
Table Collection
Row Document
Colum Field

From the above table, it is very clear how MongoDB is organized in document format compared to RDBMS.

MongoDB basically stores the data in a key-value pair, which is JSON format, which is specially designed for transferring data over a network. You can have fields of the different data types in one document; it does not force you to have the same data type for all the fields in the document. With MongoDB, the advantage is that you can insert any kind of data, but this data should be in JSON format.

Now, let’s understand the architecture of MongoDB.

Database, Collection, Document

Database

  • A database is a container of your collections.
  • A single MongoDB server typically has multiple databases.

Collection

  • A collection is basically a group of documents.
  • It is similar to a table in an RDBMS.

Document

  • The document is basically a set of key-value pairs.
  • In one document, you can have a different kind of data.
  • You can insert the same field with a different data type.

How Primary Keys Play a Different Role

In an RDBMS, as we are very well aware, the primary key is basically used to uniquely identify the data and we explicitly set the column as the primary key.

In RDBMS, there is no limitation — any column can be part of the primary key.

But if we talk about the primary key in MongoDB, the field _id is reserved for the primary key. When we insert the data without the field _id, MongoDB sets the value of it as the unique number by itself to uniquely identify the data.

If you want to set the primary key for your document, then you need to set the value of the field _id as the primary key. So, basically, in MongoDB, the field _id plays the role of the primary key.

let’s take an example of a MongoDB document:

{
_id:"12345asdfghj7890666",
name:"shubham agrawal",
email:"shubham@gmail.com",
courses:{
course_name:"scala",
fees:"5000",
duration:"3"
}
}

This is a simple example of a MongoDB document, Here you can see the field _id, which is a primary key of this document.

Why Use MongoDB?

  • Data is stored in the form of JSON-style documents.
  • Auto-sharding.
  • Replication and high availability.
  • Rich queries.
  • Index on any field.

I hope now you have some basic idea of MongoDB. In my next article, I will explain operations in MongoDB.

Originally posted on the Knoldus blog.



If you enjoyed this article and want to learn more about MongoDB, check out this collection of tutorials and articles on all things MongoDB.

MongoDB Relational database Database Document Data (computing)

Published at DZone with permission of Shubham Agarwal, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Observability Architecture: Financial Payments Introduction
  • Top 10 Pillars of Zero Trust Networks
  • A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage
  • VPN Architecture for Internal Networks

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: