Chapter Nine Flashcards
(122 cards)
What is MongoDB?
MongoDB is a NoSQL document database that stores data in JSON-like documents.
Internally uses BSON (Binary JSON) format.
What are the key characteristics of MongoDB?
Key characteristics include:
* No fixed schema
* Supports complex/nested data
* Each document must have a unique _id field.
What is the general structure of a JSON document in MongoDB?
The general structure includes:
* _id: ObjectId
* field1: String
* field2: Number
* field3: Boolean
* field4: Null
* field5: Array
* field6: Embedded document.
In MongoDB, what type of data can be stored in an array?
An array can store multiple values such as:
* Strings
* Numbers
* Objects.
Fill in the blank: MongoDB uses _______ for storing data internally.
BSON
True or False: Each document in MongoDB must have a unique _id field.
True
What is a simple example of storing e-commerce user profiles in MongoDB?
An example includes:
{
“name”: “Alice”,
“email”: “alice@example.com”,
“orders”: [
{ “item”: “Shoes”, “price”: 50 },
{ “item”: “Bag”, “price”: 30 }
]
}
What is the difference in structure between SQL and NoSQL databases?
SQL uses tables and rows, while NoSQL (MongoDB) uses collections and documents.
What command is used to insert a single document in MongoDB?
db.collection.insertOne()
What command is used to insert multiple documents in MongoDB?
db.collection.insertMany()
How can data be queried in MongoDB?
Data can be queried using commands like:
* db.collection.find()
* db.collection.findOne()
What is the command to update a document in MongoDB?
db.collection.updateOne()
What is the command to delete a document in MongoDB?
db.collection.deleteOne()
Fill in the blank: In MongoDB, the schema is _______.
Flexible (Schema On-read)
What is the command to create a collection in MongoDB?
db.createCollection()
What command would you use to find students with a GPA greater than 3.5 in MongoDB?
db.students.find({ gpa: { $gt: 3.5 } }).pretty()
What is the difference in scalability between SQL and NoSQL databases?
SQL databases scale vertically, while NoSQL (MongoDB) scales horizontally.
What does RegEx stand for?
Regular Expression
A pattern used to match strings in text-based fields.
What is RegEx used for in SQL?
Filtering with complex conditions (names, phones, codes, etc.)
What are common data issues seen in business databases?
- Messy names (e.g., jOhN, ALICE123)
- Emails in wrong format (e.g., user@.com, @gmail.com)
- Phone numbers in inconsistent style
What SQL keyword is used for basic pattern matching?
LIKE
How do you select customers whose names start with ‘A’?
SELECT * FROM Customer WHERE customerName LIKE ‘A%’
How do you select customers whose names end with ‘s’?
SELECT * FROM Customer WHERE customerName LIKE ‘%s’
How do you select customers from a city containing ‘o’?
SELECT * FROM Customer WHERE city LIKE ‘%o%’