JSON and BSON in MongoDB

In this post, we will learn the difference between JSON and BSON in MongoDB. These two are document formats and they are widely used by developers in different use cases. In MongoDB, the data is stored in BSON and viewed … Read More

Connect MongoDB Atlas Cluster Using Shell

In this post, we will learn to connect the MongoDB Atlas cluster using a shell command from our local machine. To connect a cluster we must have: Verify MongoDB Shell Version Open your Terminal or Command Prompt if you are … Read More

Create Cluster In MongoDB Atlas

In this post, we will learn to create a cluster in MongoDB Atlas. We will not learn what is MongoDB Atlas and why we need it in this post. So. let’s start creating a cluster directly. Steps to create a … Read More

Search In MongoDB Using Java

In this post, we will learn to implement a search query in MongoDB using Java. Most of the applications have search functionality. So, learning to use it will be very useful. 1. Prerequisite 2. SQL query example This query fetches … Read More

What is MongoDB?

MongoDB is an Open Source and cross-platform NoSQL Document Database. It was developed by MongoDB Inc. MongoDB is the most popular NoSQL database out there. It is a widely used database. MongoDB is a general-purpose document database. It structures the … Read More

MongoDB Document to POJO Class in Java

In this post, we will learn to map MongoDB Document to POJO Class in Java directly from org.bson.Document object to Java POJO or Java Bean. By default, MongoDB Java Driver maps MongoDB collection document to org.bson.Document object. 1. Employee document … Read More

MongoCollection in Spring Boot

In this post, we will learn to use a MongoCollection instance for database operations in the Spring Boot application. We all know that we have a spring boot data repository for MongoDB which has an interface MongoRepository and a class … Read More

Logging MongoDB Queries in Java?

In this post, we will learn to enable logging MongoDB queries in Java. For this example, we need a MongoDB driver for Java. To display the query in the log we need to set the org.mongodb.driver level to debug.

MongoDB useful commands

Create User Enable authentication And change it to  If you are using mongosh client then replace mongo with mongosh. Note: You may create other users for a specific database with a specific role Example: This means, creating a testuser with … Read More

How to check if field exists in MongoDb?

In MongoDB, we can check whether the field exists or not in two different ways: Ignore field using $exists operator Let’s say we have a collection called users and we want to query documents where the age field is exist … Read More