Posts

Showing posts from July, 2025

Upsert in MongoDB-Yusufshaikh

Image
In MongoDB, managing data often involves either inserting new documents or updating existing ones. Traditionally, developers must first check if a document exists and then decide whether to insert or update it. However, MongoDB simplifies this process with a feature called upsert , which stands for update + insert . What is Upsert? Upsert is a MongoDB operation that combines the functionality of update and insert . When you perform an update operation with the upsert option set to true , MongoDB checks whether a document matching the filter criteria exists: If the document exists , it will be updated . If the document does not exist , a new one will be inserted using the specified update values. This allows you to write cleaner and more efficient code, especially in cases where the presence of a document is uncertain. Syntax Here is the syntax for using upsert in an updateOne() operation: db.collection.updateOne( { name: "Rahul" }, // Filter ...

What is MongoDB? Introduction and History

Arpita Gaikwad University: Sri Balaji University, Pune School: School of Computer Studies Course: BCA (Bachelor of Computer Applications) Interests: NoSQL, MongoDB, and related technologies 📸 Instagram 🔗 LinkedIn 🌐 Official Website What is MongoDB? MongoDB is a popular open-source, document-oriented NoSQL database that is used for storing large amounts of unstructured or semi-structured data. Unlike traditional SQL databases that use tables and rows, MongoDB uses documents and collections , making it highly flexible and scalable. The documents are stored in BSON format (Binary JSON), which allows support for complex data types like arrays and nested objects. MongoDB is known for its high performance, horizontal scalability, and ability to handle real-time data processing needs in modern applications. History of MongoDB MongoDB was created in 2007 by a company named 10gen , initially intended to be part of a cloud computing...
Image
  JSON vs BSON : Which One Should You Use in 2025?  "Not all formats are created equal. When performance meets flexibility, the war of JSON vs BSON begins."            Introduction In today’s data-driven world, the way we store and exchange data plays a pivotal role in application speed, scalability, and user experience. Whether you're building a social media app or managing big data pipelines, you’ve likely come across JSON (JavaScript Object Notation). But have you met its binary cousin, BSON ? As MongoDB and other NoSQL databases gain popularity, developers are leaning toward BSON for performance—but why? Let’s explore what makes these formats different, where they shine, and which one YOU should choose.      What is JSON? JSON (JavaScript Object Notation) is a lightweight, text-based data format that is: Human-readable Language-independent Ideal for data exchange via REST APIs It’s used...

Topic - Transactions in MongoDB

Image
 🔄 Understanding Transactions in MongoDB: A Complete Guide MongoDB is known for its flexibility and scalability, especially in handling large amounts of unstructured data. Traditionally, MongoDB wasn’t designed for multi-document ACID transactions like relational databases. But with the release of MongoDB 4.0 and above , that changed. In this blog, we’ll explore: What transactions are Why they are important How transactions work in MongoDB Practical examples Best practices ✅ What is a Transaction? A transaction is a sequence of operations performed as a single logical unit of work. It either completes entirely or doesn’t happen at all . This concept is essential in ensuring data consistency , especially in applications like banking, inventory systems, or booking platforms. In relational databases, transactions are common. MongoDB introduced multi-document transactions starting from version 4.0 (for replica sets) and later extended support to sharded clust...

Akshada Salunkhe | Understanding MongoDB Queries

Image
  Understanding MongoDB Queries: $gt, $gte, $lt, $in, $or and More 📘 Introduction MongoDB stores data in BSON format (a binary version of JSON), which makes it easy to perform expressive and powerful queries. Query operators in MongoDB are similar to the conditionals we use in programming languages like JavaScript or Python. Here’s a quick overview of the operators we’ll cover: - $gt – Greater than - $gte – Greater than or equal to - $lt – Less than - $in – Matches any value in a list - $or – Matches documents that satisfy at least one condition These operators help us filter data based on conditions—just like using WHERE clauses in SQL. 🛠️ Procedure: Querying with MongoDB Operators 👨‍💻 Step 1: Insert Sample Data Open your MongoDB Shell or MongoDB Compass and insert a sample collection: db.students.insertMany([   { name: "Akshay", age: 22, score: 75 },   { name: "Riya", age: 20, score: 88 },   { name: "Karan", age: 24, score: ...

Creating Documents In MongoDB(Insert)

Image
• Introduction to MongoDB MongoDB is one of the most widely used NoSQL databases, known for its flexibility and scalability. Unlike traditional relational databases, MongoDB stores data in BSON format ( Binary JSON ), which allows developers to store semi-structured data. Each record in MongoDB is called a document, and documents are grouped into collections. • What is an Insert Operation in MongoDB? An insert operation in MongoDB is used to add a new document to a collection. This operation can be done through MongoDB Compass (graphical interface) or through command-line interfaces like the MongoDB shell or drivers in programming languages. There are two primary methods used for inserting data: - insertOne() for inserting a single document - insertMany() for inserting multiple documents at once • Steps to Insert Documents Using MongoDB Compass Step 1: Open MongoDB Compass Start by launching MongoDB Compass on your computer. This is the official GUI provided by MongoD...

Covered Queries and Index Queries in MongoDB

Image
  Covered Queries and Index Queries in MongoDB In MongoDB, efficient data retrieval hinges on index design. Two crucial concepts for optimizing performance are  index queries  and  covered queries . While both rely on indexes, covered queries go a step further by satisfying the  entire  query—including projections—using data in the index alone, eliminating the need to fetch full documents. 📂 What is an Index Query? An  index query  utilizes an index to narrow down search results, avoiding a full collection scan. Syntax Example: js Copy Edit db. users . createIndex ({ email : 1 }); db. users . find ({ email : "alice@example.com" }); Behind the scenes, MongoDB uses an  IXSCAN  on the  email  index instead of scanning every document, boosting speed significantly. ✅ What is a Covered Query? A  covered query  is a special case of index query where: Filter fields are indexed. Projected fields are indexed. _id  is ei...