Java MongoDB Tutorial

In this tutorial, we will learn how to use MongoDB in Java programming language.

MongoDB is a cross-platform, document-oriented database that provides, high performance, high availability, and easy scalability. MongoDB works on the concept of collections and documents.

Before getting started with the Java MongoDB tutorial, let's first familiarize ourselves with a few MongoDB basic concepts like database, collection, and document.

Database

Definition: In MongoDB, a database is a container that holds a group of collections. 

Functionality: Each database functions as a separate namespace and gets its set of files on the file system. You can have multiple databases within a single MongoDB instance. 

Usage: Suitable for segregating different applications or different user data. 

Collection

Definition: A collection in MongoDB is akin to a table in a relational database. It organizes the data as a group of documents. 

Functionality: Unlike relational databases, the collections don't enforce a schema, so documents within a collection can have different fields. 

Usage: Generally used to store similar types of documents, like users, orders, etc. 

Document

Definition: A document is a record in a MongoDB collection. It consists of key-value pairs. 

Functionality: Documents are expressed in a JSON-like format called BSON (Binary JSON), allowing them to be nested and contain arrays and other documents. 

Usage: Represents an object or an entity in the application domain. For instance, a user, a product, etc.

Mapping Relational Database to MongoDB

Collections in MongoDB are equivalent to the tables in RDBMS.

Documents in MongoDB are equivalent to the rows in RDBMS.

Fields in MongoDB are equivalent to the columns in RDBMS.
Fields (key and value pairs) are stored in a document, documents are stored in collection and collections are stored in a database.

MongoDB Tutorial for Beginners

Java MongoDB Tutorials

MongoDB + Spring Boot Tutorials

MongoDB + Spring Boot + Angular Tutorials

Comments