Core MongoDB Concepts - MongoDB Architecture & Design Flashcards

- NoSQL vs SQL databases. - Document-oriented model. - BSON format (Binary JSON)

1
Q

What is the fundamental difference between SQL and NoSQL databases?

A
  • SQL: Relational (table-based) databases.
  • NoSQL: Non-relational (document, key-value, graph, or column-based) databases.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Name three popular SQL databases

A
  • MySQL
  • PostgreSQL
  • SQL Server
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Name three popular NoSQL databases

A
  • MongoDB (document-based)
  • Redis (key-value store)
  • Cassandra (column-based)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the primary data format used in NoSQL databases?

A
  • BSON (Binary JSON) in MongoDB.
  • JSON-like documents in other NoSQL databases.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between schema-based and schema-less databases?

A
  • SQL: Schema-based (strict structure).
  • NoSQL: Schema-less (flexible structure).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you define a schema in SQL?

A

CREATE TABLE users (
id INT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(100)
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you define a schema in NoSQL (MongoDB)?

A

const userSchema = new mongoose.Schema({
name: String,
email: String
});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which database type is better suited for highly relational data?

A

SQL is better for complex relationships due to JOINs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which database type is better suited for unstructured or semi-structured data?

A

NoSQL is better due to its flexible schema.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is ACID compliance in SQL databases?

A

Atomicity, Consistency, Isolation, Durability → Ensures data integrity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Do NoSQL databases guarantee ACID compliance?

A

NoSQL typically offers eventual consistency, not full ACID compliance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is eventual consistency in NoSQL?

A

Data consistency is achieved over time, not immediately.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is BASE in NoSQL?

A

Basically Available, Soft state, Eventually consistent → The opposite of ACID

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What query language is used in SQL databases?

A

Structured Query Language (SQL)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What query language is used in MongoDB (NoSQL)?

A

MongoDB Query Language (MQL)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you perform a JOIN in SQL?

A

SELECT orders.id, customers.name
FROM orders
JOIN customers ON orders.customer_id = customers.id;

17
Q

How do you perform a JOIN-like operation in MongoDB?

A

db.orders.aggregate([
{ $lookup: {
from: “customers”,
localField: “customer_id”,
foreignField: “_id”,
as: “customer_details”
}}
]);

18
Q

What are foreign keys in SQL?

A

Constraints that link tables together

19
Q

How do NoSQL databases handle relationships?

A

By embedding documents or referencing IDs

20
Q

What is the output of this SQL query?
SELECT * FROM users WHERE age > 30;

A

Retrieves all records from users table where age is greater than 30

21
Q

How do you filter documents in MongoDB (NoSQL)?

A

db.users.find({ age: { $gt: 30 } });

22
Q

What is sharding in NoSQL databases?

A

Partitioning data across multiple servers for scalability

23
Q

What is partitioning in SQL databases?

A

Dividing large tables into smaller, more manageable pieces

24
Q

How do you scale SQL databases?

A

Vertical scaling (adding CPU, RAM, etc.)

25
Q

How do you scale NoSQL databases?

A

Horizontal scaling (adding more servers)

26
Q

What is the CAP theorem?

A

Consistency, Availability, Partition tolerance → You can achieve only two of the three in a distributed system.

27
Q

Which CAP properties do SQL and NoSQL prioritize?

A
  • SQL → Consistency and Availability.
  • NoSQL → Availability and Partition tolerance.
28
Q

What is denormalization in NoSQL?

A

Storing redundant data to reduce the need for JOINs and improve read performance

29
Q

What is normalization in SQL?

A

Organizing data into smaller tables to reduce redundancy

30
Q

What are common use cases for NoSQL databases?

A
  • Real-time analytics.
  • Content management systems.
  • IoT applications.
  • Big data processing.