Posts

CRUD Operations In MongoDB-Part 1

Image
  TOPICS: CRUD Create Read Comparison Operators Logical Operators Element Operators Array Operators Definition: CRUD operations in MongoDB refer to the four basic functions used to manage data in a database: Create, Read, Update, and Delete. C : Create – Insert new data R : Read – Retrieve data U : Update – Modify existing data D : Delete – Remove data Create (Inserting Data) The Create operation adds new documents to a collection. Methods : insertOne(): Inserts a single document. insertMany(): Inserts multiple documents at once. SYNTAX: // Insert a single document db.collection.insertOne({ key1: value1, key2: value2 }); // Insert multiple documents db.collection.insertMany([ { key1: value1 }, { key2: value2 } ]); db.users.insertOne({ name: "Alice", age: 25, email: "alice@example.com" }); db.users.insertMany([ { name: "Bob", age: 30, email: "bob@...

MongoDB Architecture

 Topics: Data Model MongoDB Instance MongoDB server Component Storage Engine Replication 1.DATA MODEL Documents The basic unit of data in MongoDB. Equivalent to a row in relational databases, but more flexible. BSON format – supports complex/nested structures. Collections A group of MongoDB documents. Equivalent to a table in relational DBs. No enforced schema, allowing different document structures. Databases Top-level container for collections. A single MongoDB instance can host multiple databases MONGODB INSTANCE In MongoDB, an instance refers to a running copy of the MongoDB server software . This is typically a process ( mongod ) running on a machine—either locally, on a server, or in the cloud. MongoDB instance : The server process ( mongod ) running on a machine. MongoDB Instance (mongod) ├── Database1 │ ├── CollectionA │ │ ├── Document1 │ │ ├── Document2 │ └── CollectionB ├── Database2 │...

MongoDB-Theory Basics

TOPICS What is MongoDB? Why MongoDB? JSON to BSON in MongoDB What is a Replica Set? ACID and BASE CAP THEOREM What is MongoDB? MongoDB is an open-source NoSQL database developed by MongoDB Inc. It stores data in a document-oriented format using BSON (a binary version of JSON). Unlike relational databases that use rows and columns, MongoDB stores data as flexible, nested documents . Why MangoDB? Feature Description Document-Based Stores data as JSON-like documents (internally as BSON). NoSQL Doesn’t use tables and rows — ideal for modern, flexible data structures. High Performance Fast read/write operations. Schema-less You don’t need to define a strict structure (schema) for data. Scalable Easily handles large datasets across multiple servers (horizontal scaling). Replicated Supports automatic failover and backup through replica sets . 1. DOCUMENT-ORIENTED MODEL Stores data as BSON (Binary JSON) documents. Each document can have a different structure ...