Posts

Showing posts from May, 2025

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

NOSQL

TOPICS What is NoSql? Types of Nosql What is Schema? Traditional Sql vs NoSql Vertical Scalability Horizondal Scalability What is NoSQL? NoSQL stands for "Not Only SQL, " non-relational databases designed to store, retrieve, and manage large volumes of unstructured, semi-structured, or flexible structured data . NoSQL databases are designed to handle: Unstructured or semi-structured data Massive volumes of data High-speed, high-throughput applications NoSQL databases do not require a fixed schema and typically do not use SQL for querying. Types of NoSQL Databases There are four main types of NoSQL databases, each suited to different use cases: Document-Based Database Key-value Stores Graph Databases Column-family stores 1. Document-Based Databases (e.g., MongoDB, CouchDB) Store data in JSON-like documents . Each document is a self-contained unit of data. Ideal for: Content management systems, user profiles, produ...

Packages and “this” Keyword

Image
THIS KEYWORD  “This Keyword” -> refers current object The main purpose of using “this” Keyword is to differntiate the formal parameter and data memebers of class,whenever the formal parameter and data memebers are same the java virtual machine get ambiguity. To differntiate between formal parameter and data memebers of the class must proceded by “this”. class Shop2{ String name1; int price1; public Shop2(String name1,int price1){ this.name1=name1; this.price1=price1; } public static void main(String[] args) { Shop2 pro1 = new Shop2("abc",20); Shop2 pro2 = new Shop2("cde",40); Shop2 pro3 = new Shop2("ghf",2000); System.out.println("product3 name:"+pro3.name1); System.out.println("product2 price:" +pro2.price1); } } //output product3 name:ghf product2 price:40 Note: /* non-static variablr “this” cannot be reffered in sta...

TYPES OF VARIABLE

Image
VARIABLE: In Java, variables serve as storage containers for data types like numbers, text, and objects. TYPES OF VARIABLES IN JAVA: (3 types) Local variable Instance variable Static variable Local variable A local variable is one that is declared inside the method body. Only that method may utilize this variable, and none of the other methods in the class are even aware that it exists. A local variable cannot be defined with “static” keyword. Instance variable: An instance variable is created when an Object class is generated and it gets destroyed when the same object class is destroyed Programmers can use access specifiers for instance variables It is not mandatory to initialize instance variables Static Variable: A variable that is declared as static is called a static variable. It cannot be local. You can create a single copy of the static variable and share it among all the instances of the class. STATIC VS NON-STATIC: FEATURE STATIC VARIABLE NON-STATIC VARIABLE Definition A s...

Data Types and Variables

Image
The explanation of data types and variables has been made simple and clear. Data Type: Data types refer to the different sizes and values that can be stored in the variable.  Two types of Data Types: Primitive data type Boolean type Boolean Numeric type character Char Integral Integer Byte short Integer Long Floating-point Float Double Non-primitive data type Class Strings Interfaces Arrays etc… Primitive Data types: Primitive data types are built-in or predefined data types and can be used directly by the user to declare variables. To find Range : Formula -2 n-1  to 2 n-1  +1 for example: Byte : 1 byte = 8bits ; so n=8 ; Apply -128 to 127 is a byte range. Examples: public class Primitive{ public static void main (String [] args){ int num = 5; // Integer (whole number) long l = 1234567l; // Long float f= 2.76f; // Floating point number double d = 21.4567 ; // no need to add 'd' char c ='D';//Character b...