Core MongoDB Concepts - MongoDB Architecture & Design Flashcards
- NoSQL vs SQL databases. - Document-oriented model. - BSON format (Binary JSON)
What is the fundamental difference between SQL and NoSQL databases?
- SQL: Relational (table-based) databases.
- NoSQL: Non-relational (document, key-value, graph, or column-based) databases.
Name three popular SQL databases
- MySQL
- PostgreSQL
- SQL Server
Name three popular NoSQL databases
- MongoDB (document-based)
- Redis (key-value store)
- Cassandra (column-based)
What is the primary data format used in NoSQL databases?
- BSON (Binary JSON) in MongoDB.
- JSON-like documents in other NoSQL databases.
What is the difference between schema-based and schema-less databases?
- SQL: Schema-based (strict structure).
- NoSQL: Schema-less (flexible structure).
How do you define a schema in SQL?
CREATE TABLE users (
id INT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(100)
);
How do you define a schema in NoSQL (MongoDB)?
const userSchema = new mongoose.Schema({
name: String,
email: String
});
Which database type is better suited for highly relational data?
SQL is better for complex relationships due to JOINs.
Which database type is better suited for unstructured or semi-structured data?
NoSQL is better due to its flexible schema.
What is ACID compliance in SQL databases?
Atomicity, Consistency, Isolation, Durability → Ensures data integrity
Do NoSQL databases guarantee ACID compliance?
NoSQL typically offers eventual consistency, not full ACID compliance.
What is eventual consistency in NoSQL?
Data consistency is achieved over time, not immediately.
What is BASE in NoSQL?
Basically Available, Soft state, Eventually consistent → The opposite of ACID
What query language is used in SQL databases?
Structured Query Language (SQL)
What query language is used in MongoDB (NoSQL)?
MongoDB Query Language (MQL)
How do you perform a JOIN in SQL?
SELECT orders.id, customers.name
FROM orders
JOIN customers ON orders.customer_id = customers.id;
How do you perform a JOIN-like operation in MongoDB?
db.orders.aggregate([
{ $lookup: {
from: “customers”,
localField: “customer_id”,
foreignField: “_id”,
as: “customer_details”
}}
]);
What are foreign keys in SQL?
Constraints that link tables together
How do NoSQL databases handle relationships?
By embedding documents or referencing IDs
What is the output of this SQL query?
SELECT * FROM users WHERE age > 30;
Retrieves all records from users
table where age
is greater than 30
How do you filter documents in MongoDB (NoSQL)?
db.users.find({ age: { $gt: 30 } });
What is sharding in NoSQL databases?
Partitioning data across multiple servers for scalability
What is partitioning in SQL databases?
Dividing large tables into smaller, more manageable pieces
How do you scale SQL databases?
Vertical scaling (adding CPU, RAM, etc.)
How do you scale NoSQL databases?
Horizontal scaling (adding more servers)
What is the CAP theorem?
Consistency, Availability, Partition tolerance → You can achieve only two of the three in a distributed system.
Which CAP properties do SQL and NoSQL prioritize?
- SQL → Consistency and Availability.
- NoSQL → Availability and Partition tolerance.
What is denormalization in NoSQL?
Storing redundant data to reduce the need for JOINs and improve read performance
What is normalization in SQL?
Organizing data into smaller tables to reduce redundancy
What are common use cases for NoSQL databases?
- Real-time analytics.
- Content management systems.
- IoT applications.
- Big data processing.