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 Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • MongoDB to Couchbase for Developers, Part 1: Architecture
  • MongoDB to Couchbase: An Introduction to Developers and Experts
  • Manage Hierarchical Data in MongoDB With Spring
  • Java and MongoDB Integration: A CRUD Tutorial [Video Tutorial]

Trending

  • Building a Skill-Based Agentic Reviewer with Claude Code: A Practical Guide Using Skills.MD, MCP Servers, Tools, and Tasks
  • A 5-Step SOC Guide That Meets RBI Expectations and Strengthens Security Operations
  • Self-Hosted Inference Doesn’t Have to Be a Nightmare: How to Use GPUStack
  • Why We Chose Iceberg Over Delta After Evaluating Both at Scale
  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.

By 
Shubham Agarwal user avatar
Shubham Agarwal
·
May. 03, 18 · Analysis
Likes (9)
Comment
Save
Tweet
Share
12.8K 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:"[email protected]",
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. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • MongoDB to Couchbase for Developers, Part 1: Architecture
  • MongoDB to Couchbase: An Introduction to Developers and Experts
  • Manage Hierarchical Data in MongoDB With Spring
  • Java and MongoDB Integration: A CRUD Tutorial [Video Tutorial]

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook