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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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
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

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

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
  • Spring Data: Data Auditing Using JaVers and MongoDB

Trending

  • DZone's Article Submission Guidelines
  • Docker Base Images Demystified: A Practical Guide
  • Unlocking AI Coding Assistants Part 4: Generate Spring Boot Application
  • The Modern Data Stack Is Overrated — Here’s What Works
  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.5K 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.

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
  • Spring Data: Data Auditing Using JaVers and MongoDB

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!