Chapter Nine Flashcards

(122 cards)

1
Q

What is MongoDB?

A

MongoDB is a NoSQL document database that stores data in JSON-like documents.

Internally uses BSON (Binary JSON) format.

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

What are the key characteristics of MongoDB?

A

Key characteristics include:
* No fixed schema
* Supports complex/nested data
* Each document must have a unique _id field.

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

What is the general structure of a JSON document in MongoDB?

A

The general structure includes:
* _id: ObjectId
* field1: String
* field2: Number
* field3: Boolean
* field4: Null
* field5: Array
* field6: Embedded document.

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

In MongoDB, what type of data can be stored in an array?

A

An array can store multiple values such as:
* Strings
* Numbers
* Objects.

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

Fill in the blank: MongoDB uses _______ for storing data internally.

A

BSON

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

True or False: Each document in MongoDB must have a unique _id field.

A

True

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

What is a simple example of storing e-commerce user profiles in MongoDB?

A

An example includes:
{
“name”: “Alice”,
“email”: “alice@example.com”,
“orders”: [
{ “item”: “Shoes”, “price”: 50 },
{ “item”: “Bag”, “price”: 30 }
]
}

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

What is the difference in structure between SQL and NoSQL databases?

A

SQL uses tables and rows, while NoSQL (MongoDB) uses collections and documents.

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

What command is used to insert a single document in MongoDB?

A

db.collection.insertOne()

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

What command is used to insert multiple documents in MongoDB?

A

db.collection.insertMany()

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

How can data be queried in MongoDB?

A

Data can be queried using commands like:
* db.collection.find()
* db.collection.findOne()

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

What is the command to update a document in MongoDB?

A

db.collection.updateOne()

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

What is the command to delete a document in MongoDB?

A

db.collection.deleteOne()

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

Fill in the blank: In MongoDB, the schema is _______.

A

Flexible (Schema On-read)

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

What is the command to create a collection in MongoDB?

A

db.createCollection()

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

What command would you use to find students with a GPA greater than 3.5 in MongoDB?

A

db.students.find({ gpa: { $gt: 3.5 } }).pretty()

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

What is the difference in scalability between SQL and NoSQL databases?

A

SQL databases scale vertically, while NoSQL (MongoDB) scales horizontally.

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

What does RegEx stand for?

A

Regular Expression

A pattern used to match strings in text-based fields.

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

What is RegEx used for in SQL?

A

Filtering with complex conditions (names, phones, codes, etc.)

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

What are common data issues seen in business databases?

A
  • Messy names (e.g., jOhN, ALICE123)
  • Emails in wrong format (e.g., user@.com, @gmail.com)
  • Phone numbers in inconsistent style
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What SQL keyword is used for basic pattern matching?

A

LIKE

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

How do you select customers whose names start with ‘A’?

A

SELECT * FROM Customer WHERE customerName LIKE ‘A%’

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

How do you select customers whose names end with ‘s’?

A

SELECT * FROM Customer WHERE customerName LIKE ‘%s’

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

How do you select customers from a city containing ‘o’?

A

SELECT * FROM Customer WHERE city LIKE ‘%o%’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How do you select customers whose names start with J to M?
SELECT customerName, city, country FROM Customer WHERE customerName LIKE '[J-M]%'
26
How do you select customers whose names do NOT start with M or H?
SELECT customerNumber, customerName FROM Customer WHERE customerName LIKE '[^MH]%'
27
How do you select customers with phone numbers containing only dashes?
SELECT * FROM customers WHERE phone LIKE '%-%' AND phone NOT LIKE '%(%' AND phone NOT LIKE '%)%'
28
What is a key limitation of SQL Server's RegEx support?
Regular expression syntax is platform-dependent
29
Which SQL server management tool is mentioned for RegEx syntax?
SQL Server Management Studio (SSMS)
30
What SQL command is used to find classes in a room with descriptions starting with 'BA'?
SELECT * FROM DEMO_CLASSROOM WHERE DESCR LIKE 'BA%'
31
What SQL command uses REGEXP_LIKE to find classes in a room with descriptions starting with 'BA'?
SELECT * FROM DEMO_CLASSROOM WHERE REGEXP_LIKE (DESCR, '^BA')
32
What SQL command finds classes with 'BA' anywhere in the description?
SELECT * FROM DEMO_CLASSROOM WHERE DESCR LIKE '%BA%'
33
What SQL command finds classes with descriptions starting with 'BA' and containing the digit '1'?
SELECT * FROM DEMO_CLASSROOM WHERE DESCR LIKE 'BA%1%'
34
What SQL command finds classes where the second letter is 'A' and contains '1'?
SELECT * FROM DEMO_CLASSROOM WHERE DESCR LIKE '_A%1%'
35
What SQL command excludes names with 'B' or 'A' in the description?
SELECT * FROM DEMO_CLASSROOM WHERE REGEXP_LIKE (DESCR, '^[^AB]')
36
What SQL command selects employees with names that contain at least one 'r'?
SELECT EMPLOYEEID, EMPLOYEENAME FROM EMPLOYEE_T WHERE regexp_like(EMPLOYEENAME,'r+')
37
What SQL command selects employees with names that contain exactly two 'r's?
SELECT EMPLOYEEID, EMPLOYEENAME FROM EMPLOYEE_T WHERE regexp_like(EMPLOYEENAME,'r{2}')
38
What SQL command excludes employees whose names contain two 'r's?
SELECT EMPLOYEEID, EMPLOYEENAME FROM EMPLOYEE_T WHERE NOT regexp_like(EMPLOYEENAME,'r{2}')
39
What SQL command selects classes that must contain at least one digit?
SELECT * FROM DEMO_CLASSROOM WHERE REGEXP_LIKE (DESCR, '[0-9]')
40
What SQL command selects classes that must contain between one to three digits?
SELECT * FROM DEMO_CLASSROOM WHERE REGEXP_LIKE (DESCR, '[0-9]{1,3}')
41
What SQL command matches if the digits are between 0 and 9, excluding 1?
SELECT * FROM DEMO_CLASSROOM WHERE REGEXP_LIKE (DESCR, '[02-9]{3}')
42
What SQL command excludes selections if 'BA' is included in the description?
SELECT * FROM DEMO_CLASSROOM WHERE DESCR NOT LIKE 'BA%'
43
What SQL command selects descriptions where a number starts with '1' and has at least two digits after?
SELECT * FROM DEMO_CLASSROOM WHERE REGEXP_LIKE (DESCR, '1\d\d')
44
Fill in the blank: The SQL command to insert a new classroom with ID 'N101' and description 'NeedBAinTheMiddle' is _______.
INSERT INTO DEMO_CLASSROOM VALUES ('N101', 'NeedBAinTheMiddle', 101)
45
Fill in the blank: The SQL command to insert a new classroom with ID 'N102' and description 'BA-Start with it' is _______.
INSERT INTO DEMO_CLASSROOM VALUES ('N102', 'BA-Start with it', 102)
46
Fill in the blank: The SQL command to insert a new classroom with ID 'N103' and description 'Habitat' is _______.
INSERT INTO DEMO_CLASSROOM VALUES ('N103', 'Habitat', 103)
47
Fill in the blank: The SQL command to insert a new classroom with ID 'N104' and description 'HANDLEY-134' is _______.
INSERT INTO DEMO_CLASSROOM VALUES ('N104', 'HANDLEY-134', 104)
48
Fill in the blank: The SQL command to insert a new classroom with ID 'N105' and description 'Alcon' is _______.
INSERT INTO DEMO_CLASSROOM VALUES ('N105', 'Alcon', 105)
49
Fill in the blank: The SQL command to insert a new classroom with ID 'N106' and description '1234567' is _______.
INSERT INTO DEMO_CLASSROOM VALUES ('N106', '1234567', 106)
50
Fill in the blank: The SQL command to insert a new classroom with ID 'N107' and description 'baable' is _______.
INSERT INTO DEMO_CLASSROOM VALUES ('N107', 'baable', 107)
51
Fill in the blank: The SQL command to insert a new classroom with ID 'N108' and description 'baaable' is _______.
INSERT INTO DEMO_CLASSROOM VALUES ('N108', 'baaable', 108)
52
Fill in the blank: The SQL command to insert a new classroom with ID 'N109' and description 'baaaable' is _______.
INSERT INTO DEMO_CLASSROOM VALUES ('N109', 'baaaable', 109)
53
What does JSON stand for?
Javascript Object Notation
54
List the six native JSON value types.
string, number, boolean, null, array, object
55
Does JSON guarantee key order inside an object?
No
56
Which JSON type is missing when you need a timestamp?
Date (not native)
57
Why did MongoDB invent BSON?
Typed binary encoding that is faster & supports more data types
58
Name three BSON-specific types.
ObjectId, Date, Decimal128
59
Maximum size of a single MongoDB document?
16 MB
60
Atlas free tier name?
M0
61
Default Atlas Web Shell program?
mongosh
62
Command to list databases in mongosh.
show dbs
63
Insert one document into collection 'contacts'.
db.contacts.insertOne({...})
64
Query for docs where age > 30.
db.col.find({ age: { $gt:30 } })
65
Update field 'status' to 'active'.
db.col.updateMany({}, { $set:{ status:'active' } })
66
Delete docs where flag = true.
db.col.deleteMany({ flag:true })
67
Regex search for names starting with A (case-insens.).
db.col.find({ name:/^A/i })
68
Create compound index on city asc, age desc.
db.people.createIndex({ city:1, age:-1 })
69
Export collection 'orders' to JSON.
mongoexport --collection=orders --out=orders.json
70
Difference between embed vs reference?
Embed for co-accessed data; reference for shared or unbounded data
71
What CLI installs MongoDB cluster via Atlas?
atlas setup
72
Ubuntu service command to start mongod.
sudo systemctl start mongod
73
Meaning of the '_id' field.
Primary key; unique ObjectId unless you supply custom
74
What operator adds an item to an array only if missing?
$addToSet
75
True/False: A deleted collection’s indexes remain on disk.
False
76
Aggregation stage to group and sum.
$group with $sum accumulator
77
Which CRUD verb is missing in CRUELS?
None (S stands for Search)
78
Size limit of Atlas M0 storage?
512 MB (subject to Atlas docs)
79
GUI tool bundled with MongoDB installer.
MongoDB Compass
80
Name two update operators besides $set.
$inc, $unset, $push, $pull
81
How to view collection stats.
db.collection.stats()
82
mongoexport vs mongodump – output format?
mongoexport → JSON/CSV; mongodump → Binary BSON files
83
Is JSON whitespace-sensitive?
No (ignored outside strings)
84
What is the default port for a local mongod?
27017
85
Which aggregation stage must come first?
None are mandatory, but $match early improves performance
86
Command to switch database in mongosh.
use
87
How to limit query output to 5 docs.
db.col.find().limit(5)
88
The keyword to skip n docs in a find cursor.
skip(n)
89
How to update exactly one doc even if filter matches many?
updateOne()
90
Which Atlas tab loads ready-made datasets?
'Load Sample Data'
91
Binary size advantage of BSON over JSON?
Smaller because no quotes around keys and typed lengths
92
Why does BSON use little-endian integers?
Faster decoding on common CPUs
93
Which BSON type carries timezone-aware dates?
Date (stored as 64-bit epoch ms, UTC)
94
What is MongoDB Compass?
A GUI for MongoDB that allows users to interact with their databases visually. ## Footnote Download link: https://www.mongodb.com/try/download/compass
95
What is the purpose of MongoDB Community Server?
To provide a free version of MongoDB for local installation and use. ## Footnote Download link: https://www.mongodb.com/try/download/community-edition
96
What is the MongoDB shell?
An interactive JavaScript interface for querying and updating MongoDB data. ## Footnote Download link: https://www.mongodb.com/try/download/shell
97
Define JSON.
A data interchange format for moving data from one place to another.
98
List the benefits of JSON.
* Easy for humans to read and write * Easy for machines to parse and generate
99
What are the three elements of JSON?
* Object * Value * Array
100
What does BSON stand for?
Binary JSON, a variant of JSON used by MongoDB.
101
What are the organizing constructs for document databases like MongoDB?
* Database * Collection * Document
102
True or False: A Collection in MongoDB enforces a schema.
False
103
What must documents in MongoDB incorporate?
A Primary Key as a unique identifier.
104
What command is used to list all databases in MongoDB?
show dbs
105
How do you switch to a specific database in MongoDB? Provide an example.
use
106
How can you check all collections present in the current database?
show collections
107
Write a command to create a collection named 'post'.
db.createCollection('post')
108
Insert a document into the post collection with _id = 123456890 and title as 'some title'.
db.post.insert({ '_id': '123456890', 'mytitle': 'some title' })
109
Display all documents from the post collection.
db.post.find({})
110
How do you search for documents where 'mytitle' contains the word 'some'?
db.post.find({ 'mytitle': /some/ })
111
Update the 'mytitle' from 'some title' to 'new title' in the post collection.
db.post.update({ 'mytitle': 'some title' }, { $set: { 'mytitle': 'new title' } })
112
Delete all documents from post where 'mytitle' is 'some title'.
db.post.remove({ 'mytitle': 'some title' })
113
Create a collection called 'inventory'.
db.createCollection('inventory')
114
Insert multiple documents into inventory that contain nested fields like size.
db.inventory.insertMany([{ item: 'journal', qty: 25, tags: ['blank', 'red'], size: { h: 14, w: 21, uom: 'cm' } }, { item: 'mat', qty: 85, tags: ['gray'], size: { h: 27.9, w: 35.5, uom: 'cm' } }, { item: 'mousepad', qty: 25, tags: ['gel', 'blue'], size: { h: 19, w: 22.85, uom: 'cm' } }])
115
How do you retrieve all documents from inventory using a pretty format?
db.inventory.find({}).pretty()
116
What is wrong with the command 'Db.inventory.find({"qty": {$lt: 80}})'?
Incorrect case - Db should be db
117
Explain the difference between insertOne() and insertMany().
insertOne() adds a single document, while insertMany() adds multiple documents.
118
What is the purpose of .pretty() in MongoDB queries?
Formats query results in a clean, readable way.
119
Write a query to count the number of documents in the inventory collection.
db.inventory.find({}).pretty().count()
120
How would you find all documents in inventory where the value 'red' exists in the tags array?
db.inventory.find({tags: 'red'})
121
Find all documents where the quantity (qty) is less than 80.
db.inventory.find({ 'qty': { $lt: 80 } })
122
Will the following command work? 'db.trypost.insert([...])'. If not, fix it.
No, it should be 'db.trypost.insertMany([...])'