Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: How does it differ from rows in SQL databases? Explain a bit more A document in MongoDB is a record represented as a JSON-like object (BSON format) that contains field-value pairs. It can have a flexible st…
Short answer: mount of data the system needs to scan. MongoDB creates indexes on fields that are queried frequently. Real-world example (ShopNest) ShopNest adds an index on Orders(CustomerId, CreatedAt) because “my recen…
Short answer: How is it different from SQL indexes? Indexing in MongoDB is a mechanism to improve query performance by reducing the amount of data the system needs to scan. MongoDB creates indexes on fields that are quer…
Short answer: The $in operator is used to match values in a specified array. It checks if the value of a field is equal to any value in the provided array. Example code db.collection.find({ age: { $in: [25, 30, 35] } });…
Short answer: utomatically. Sharded Cluster: Used for horizontal scaling. It splits data across multiple servers (shards) based on a shard key. Each shard holds a portion of the data, and a mongos router directs queries…
Short answer: Replica Set: A group of MongoDB servers that maintain the same data. Explain a bit more It provides high availability and data redundancy by replicating data across multiple servers. If the primary server g…
Short answer: find(): Returns a cursor to all documents that match the query. You can iterate over the results using .forEach() or convert them to an array with .toArray(). Example code db.collection.find({ age: { $gt: 3…
Short answer: And count occurrences { $sort: { count: -1 } } // Sort by count in descending order ]); nd count occurrences { $sort: { count: -1 } } // Sort by count in descending order ]); And count occurrences { $sort:…
Short answer: How do you use it? The Aggregation Framework in MongoDB is used to perform complex data processing tasks such as grouping, filtering, sorting, and reshaping documents. It uses a pipeline of stages to proces…
Short answer: ccessed in the database. Since MongoDB is schema-less, data modeling involves deciding how to structure documents, collections, and their relationships (embedded vs. referenced documents) to balance perform…
Short answer: Data modeling in MongoDB refers to the design of how data will be stored, organized, and accessed in the database. Since MongoDB is schema-less, data modeling involves deciding how to structure documents, c…
Short answer: A document schema defines the structure, rules, and validations for documents in a collection. MongoDB is schema-less by default, but you can enforce schema validation rules using MongoDB schema validation.…
Short answer: MongoDB Atlas is a fully-managed cloud database service provided by MongoDB Inc. It offers: Automated backups, scaling, and updates. Multi-cloud support (AWS, GCP, Azure). Advanced security features like en…
Short answer: Database security refers to the practices, tools, and measures used to protect a database from unauthorized access, misuse, modification, or destruction of its data. Explain a bit more It ensures the confid…
Short answer: s data, not executable code. - Example in MySQL (using PDO in PHP) $stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username AND password = :password'); $stmt->execute(['username' => $u…
Short answer: SQL Injection is a type of attack where an attacker inserts or manipulates malicious SQL code into a query, which can compromise the database. Explain a bit more It usually happens when user input is improp…
Short answer: fter the full backup until the specified point in time. SQL Server RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backups\MyDatabase.bak'; RESTORE LOG MyDatabase FROM DISK = 'C:\Backups\MyDatabase_log.trn' WIT…
Short answer: Point-in-time recovery (PITR) allows you to restore a database to a specific moment in time, which can be crucial in scenarios where: Data corruption or accidental deletion occurs. Explain a bit more You wa…
Short answer: Database scaling refers to increasing a database's ability to handle more workload—either by increasing the resources available to a single instance or distributing the load across multiple instances. Real-…
Short answer: A read replica is a copy of a database that is used to offload read-only queries from the primary database (master). Explain a bit more It is particularly useful for handling high read traffic and improving…
Short answer: Database caching involves storing frequently accessed data in a faster storage layer (e.g., memory) so that future requests for the same data can be served more quickly, reducing the need to query the datab…
Short answer: Query optimization is the process of improving the efficiency of SQL queries to reduce resource consumption and improve response time. Explain a bit more The goal is to make sure that queries are executed u…
Short answer: Event sourcing is a pattern where the state of an application is determined by a sequence of events, rather than storing the current state directly in the database. Explain a bit more How it works: Instead…
Short answer: A materialized view is a database object that stores the results of a query physically, unlike a regular view, which computes its result dynamically. Explain a bit more Advantages: Faster query response tim…
Short answer: A time-series database (TSDB) is optimized for storing, querying, and managing time-stamped data (data associated with timestamps), often used for tracking events or metrics over time. Explain a bit more Us…
SQL & Databases SQL Server Tutorial · SQL
Short answer: How does it differ from rows in SQL databases?
A document in MongoDB is a record represented as a JSON-like object (BSON format) that contains field-value pairs. It can have a flexible structure, meaning each document in a collection may contain different fields and data types. Differences from SQL Rows: In SQL, a row is a fixed set of columns (defined by the schema), while in MongoDB, a document is more flexible and can vary in structure. A row in SQL is constrained by a schema, whereas a document in MongoDB can store complex, nested data structures (arrays, sub-documents).
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: mount of data the system needs to scan. MongoDB creates indexes on fields that are queried frequently.
ShopNest adds an index on Orders(CustomerId, CreatedAt) because “my recent orders” is queried constantly.
SQL & Databases SQL Server Tutorial · SQL
Short answer: How is it different from SQL indexes? Indexing in MongoDB is a mechanism to improve query performance by reducing the amount of data the system needs to scan. MongoDB creates indexes on fields that are queried frequently. Differences from SQL indexes: MongoDB uses B-tree indexes (by default) but also supports other types like hashed indexes, geospatial indexes, and text indexes. SQL indexes are typically built on a…
fixed schema and are more rigid, while MongoDB indexes can be dynamic, allowing indexing on any field within a document. MongoDB supports compound indexes and array indexes for more complex queries.
ShopNest adds an index on Orders(CustomerId, CreatedAt) because “my recent orders” is queried constantly.
SQL & Databases SQL Server Tutorial · SQL
Short answer: The $in operator is used to match values in a specified array. It checks if the value of a field is equal to any value in the provided array.
db.collection.find({ age: { $in: [25, 30, 35] } }); This query finds all documents where the age field is 25, 30, or 35.
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: utomatically. Sharded Cluster: Used for horizontal scaling. It splits data across multiple servers (shards) based on a shard key. Each shard holds a portion of the data, and a mongos router directs queries to the correct shard. Sharding helps manage large datasets by distributing the load.
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: Replica Set: A group of MongoDB servers that maintain the same data.
It provides high availability and data redundancy by replicating data across multiple servers. If the primary server goes down, one of the secondaries can be promoted to primary automatically. Sharded Cluster: Used for horizontal scaling. It splits data across multiple servers (shards) based on a shard key. Each shard holds a portion of the data, and a mongos router directs queries to the correct shard. Sharding helps manage large datasets by distributing the load.
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: find(): Returns a cursor to all documents that match the query. You can iterate over the results using .forEach() or convert them to an array with .toArray().
db.collection.find({ age: { $gt: 30 } }); findOne(): Returns the first document that matches the query, or null if no document is found. Example: db.collection.findOne({ name: "Alice" });
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: And count occurrences { $sort: { count: -1 } } // Sort by count in descending order ]); nd count occurrences { $sort: { count: -1 } } // Sort by count in descending order ]); And count occurrences { $sort: { count: -1 } } // Sort by count in descending order ]); nd count occurrences { $sort: { count: -1 } } // Sort by count in descending order ]);
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: How do you use it? The Aggregation Framework in MongoDB is used to perform complex data processing tasks such as grouping, filtering, sorting, and reshaping documents. It uses a pipeline of stages to process documents:
db.collection.aggregate([ { $match: { status: "active" } }, // Filter documents { $group: { _id: "$age", count: { $sum: 1 } } }, // Group by age and count occurrences { $sort: { count: -1 } } // Sort by count in descending order ]);
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: ccessed in the database. Since MongoDB is schema-less, data modeling involves deciding how to structure documents, collections, and their relationships (embedded vs. referenced documents) to balance performance, scalability, and ease of querying.
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: Data modeling in MongoDB refers to the design of how data will be stored, organized, and accessed in the database. Since MongoDB is schema-less, data modeling involves deciding how to structure documents, collections, and their relationships (embedded vs. referenced documents) to balance performance, scalability, and ease of querying.
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: A document schema defines the structure, rules, and validations for documents in a collection. MongoDB is schema-less by default, but you can enforce schema validation rules using MongoDB schema validation. Example: db.createCollection("users", { validator: { $jsonSchema: { bsonType: "object", required: ["name", "email"], properties: { name: { bsonType: "string" }, email: { bsonType: "string" } }
}
} });
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: MongoDB Atlas is a fully-managed cloud database service provided by MongoDB Inc. It offers: Automated backups, scaling, and updates. Multi-cloud support (AWS, GCP, Azure). Advanced security features like encryption and IP whitelisting. Monitoring and performance optimization tools. Global replication across different regions.
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: Database security refers to the practices, tools, and measures used to protect a database from unauthorized access, misuse, modification, or destruction of its data.
It ensures the confidentiality, integrity, and availability (often referred to as the CIA triad) of the data stored within the database. Why it's important: Confidentiality: Protects sensitive data from unauthorized access (e.g., personal information, financial data). Integrity: Ensures data remains accurate, consistent, and unaltered by unauthorized users. Availability: Ensures data is available when needed and prevents disruptions from threats like ransomware or DDoS attacks.
SQL & Databases SQL Server Tutorial · SQL
Short answer: s data, not executable code. - Example in MySQL (using PDO in PHP) $stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username AND password = :password'); $stmt->execute(['username' => $username, 'password' => $password]); ● Input Validation: Always validate user input by checking for expected data types, lengths, and ranges. s data, not…… executable code. - Example in MySQL (using PDO in PHP) $stmt =…
$pdo->prepare('SELECT * FROM users WHERE username = :username AND password = :password'); $stmt->execute(['username' => $username, 'password' => $password]); ● Input Validation: Always validate user input by checking for expected data types, lengths, and ranges. Escaping User Input:… s data, not executable code. - Example in MySQL (using PDO in PHP) $stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username AND password = :password'); $stmt->execute(['username' => $username, 'password' => $password]); ● Input Validation: Always validate user input by checking for expected data types, lengths, and ranges. Escaping…
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: SQL Injection is a type of attack where an attacker inserts or manipulates malicious SQL code into a query, which can compromise the database.
It usually happens when user input is improperly sanitized or validated. Prevention techniques: Use Prepared Statements/Parameterized Queries: This ensures that user input is treated as data, not executable code. - Example in MySQL (using PDO in PHP) $stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username AND password = :password'); $stmt->execute(['username' => $username, 'password' => $password]); ● Input Validation: Always validate user input by checking for expected data types, lengths, and ranges. Escaping User Input: If parameters cannot be parameterized, make sure all user input is properly escaped. Least Privilege Principle: Limit database user permissions to only those necessary to perform their tasks. Web Application Firewalls (WAF): Use WAFs to detect and block SQL injection attacks.
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: fter the full backup until the specified point in time. SQL Server RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backups\MyDatabase.bak'; RESTORE LOG MyDatabase FROM DISK = 'C:\Backups\MyDatabase_log.trn' WITH STOPAT = '2023-09-14T15:30:00'; -- Restore up to a specific time PostgreSQL
To enable point-in-time recovery, you need to restore a base backup, then use WAL (Write-Ahead Logging) archives to apply changes until the desired point. fter the full backup until the specified point in time. SQL Server Example: RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backups\MyDatabase.bak'; RESTORE LOG MyDatabase FROM DISK = 'C:\Backups\MyDatabase_log.trn' WITH STOPAT = '2023-09-14T15:30:00'; -- Restore up to a specific time PostgreSQL Example: To enable point-in-time recovery, you need to restore a base backup, then use WAL (Write-Ahead Logging) archives to apply changes until the desired point. fter the full backup until the specified point in time. SQL Server Example: RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backups\MyDatabase.bak'; RESTORE LOG MyDatabase FROM DISK = 'C:\Backups\MyDatabase_log.trn' WITH STOPAT = '2023-09-14T15:30:00'; -- Restore up to a specific time PostgreSQL Example: To enable point-in-time recovery, you need to restore a base backup, then use WAL (Write-Ahead Logging) archives to apply changes until the desired point. You would also set the restore_command in recovery.conf and specify the recovery_target_time. fter the full backup until the specified point in time. SQL Server Example: RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backups\MyDatabase.bak'; RESTORE LOG MyDatabase FROM DISK = 'C:\Backups\MyDatabase_log.trn' WITH STOPAT = '2023-09-14T15:30:00'; -- Restore up to a specific time PostgreSQL Example: To enable point-in-time recovery, you need to restore a base backup, then use WAL (Write-Ahead Logging) archives to apply changes until the desired point. You would also set the restore_command in recovery.conf and specify the recovery_target_time.
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: Point-in-time recovery (PITR) allows you to restore a database to a specific moment in time, which can be crucial in scenarios where: Data corruption or accidental deletion occurs.
You want to rollback to a specific moment before a harmful event. How it works: First, a full backup is restored. Then, transaction log backups are applied, allowing you to replay changes made after the full backup until the specified point in time. SQL Server
RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backups\MyDatabase.bak'; RESTORE LOG MyDatabase FROM DISK = 'C:\Backups\MyDatabase_log.trn' WITH STOPAT = '2023-09-14T15:30:00'; -- Restore up to a specific time PostgreSQL Example: To enable point-in-time recovery, you need to restore a base backup, then use WAL (Write-Ahead Logging) archives to apply changes until the desired point. You would also set the restore_command in recovery.conf and specify the recovery_target_time.
SQL & Databases SQL Server Tutorial · SQL
Short answer: Database scaling refers to increasing a database's ability to handle more workload—either by increasing the resources available to a single instance or distributing the load across multiple instances.
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: A read replica is a copy of a database that is used to offload read-only queries from the primary database (master).
It is particularly useful for handling high read traffic and improving database scalability. How it helps with scaling: By distributing read requests across multiple replicas, the primary database can focus on write operations, reducing the load on the master. It improves performance by providing additional resources dedicated to read operations. Example: In a web application with high traffic, multiple read replicas can serve read-heavy queries, while writes are only made to the master database. Note: Read replicas are usually asynchronous, meaning there can be a slight delay in replication. For critical real-time reads, this might not be suitable.
ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.
SQL & Databases SQL Server Tutorial · SQL
Short answer: Database caching involves storing frequently accessed data in a faster storage layer (e.g., memory) so that future requests for the same data can be served more quickly, reducing the need to query the database repeatedly.
How it improves performance: Reduces database load: Instead of querying the database every time data is requested, the cache can provide instant access to commonly requested data. Improves response time: Caching data in-memory (using technologies like Redis or Memcached) makes it accessible in nanoseconds, compared to the millisecond access time of traditional disk-based databases. Reduces latency: Caching significantly reduces the time taken to fetch data, improving the overall user experience. Example: Frequently accessed user profiles in a web application can be cached using Redis, so that subsequent requests don't have to query the database again.
SQL & Databases SQL Server Tutorial · SQL
Short answer: Query optimization is the process of improving the efficiency of SQL queries to reduce resource consumption and improve response time.
The goal is to make sure that queries are executed using the most efficient execution plan possible. Why it's important: Optimized queries help reduce CPU load, memory consumption, and I/O operations, improving overall system performance. It prevents slow queries that might degrade the user experience or cause resource contention in high-traffic applications. Common techniques: Indexing: Using appropriate indexes can drastically reduce query times. **Avoiding SELECT ***: Only select the necessary columns instead of selecting all columns. Query refactoring: Break down complex queries into simpler ones, or replace subqueries with joins when possible. Using appropriate joins: Ensure proper joins are used (e.g., INNER JOIN vs. OUTER JOIN). Limit result set: Use LIMIT or TOP to reduce the number of rows returned.
SQL & Databases SQL Server Tutorial · SQL
Short answer: Event sourcing is a pattern where the state of an application is determined by a sequence of events, rather than storing the current state directly in the database.
How it works: Instead of storing the current state of an entity, each change to that entity (event) is stored as an immutable event in an event store. The state can be reconstructed by replaying the events. Advantages: You have a complete audit trail of changes. Enables eventual consistency and can scale well in distributed systems. Use cases: CQRS (Command Query Responsibility Segregation), systems requiring full audit logs, and systems that need to capture historical data changes.
SQL & Databases SQL Server Tutorial · SQL
Short answer: A materialized view is a database object that stores the results of a query physically, unlike a regular view, which computes its result dynamically.
Advantages: Faster query response times as the results are precomputed and stored. Can be refreshed periodically (e.g., every hour or after specific events) to keep the data up to date. Use cases: Reporting, data warehousing, and aggregation-heavy applications. Example: A materialized view could aggregate sales data by day, allowing a query to retrieve the precomputed values instead of performing costly aggregation on the fly.
SQL & Databases SQL Server Tutorial · SQL
Short answer: A time-series database (TSDB) is optimized for storing, querying, and managing time-stamped data (data associated with timestamps), often used for tracking events or metrics over time.
Use cases: IoT data, server logs, stock prices, sensor data, application monitoring, etc. Characteristics: Data is ordered by timestamps. Efficient for inserting large volumes of data continuously. Optimized for queries that focus on time ranges (e.g., finding data from a particular hour or day). Examples: InfluxDB, TimescaleDB, Prometheus.
Install Toolliyo like an app Free
Home-screen access to tutorials, coding practice & career tools — no app store needed.
On iPhone/iPad: tap Share then Add to Home Screen.