Lecture 12- MongoDB Flashcards
What is a non-relational database?
- Polymorphic data structure
- Flexible schemas
- Easy to scale large workloads
Describe the document model
- JSON notation
- Field-value pairs are separated by colon
- Fields must be enclosed within quotation marks (string values are often quoted as well)
- Two field-values are separated by commas
What is a document?
A way to organize and store data as a set of field-value pairs in MongoDB
What is a collection?
An organized store of documents in MongoDB, usually with common fields between documents
What is the different between these two documents?
Two documents in the same collection but with different fields
Whats the difference between tabular (relational) data model vs document data model?
- Tabular = related data is split across multiple records and tables
- Document = related data is contained in a single, rich document
Describe MongoDB query language
- simple syntax
- designed to query documents
- only queries a single collection
What is this query doing?
Find documents (in people collection) with the age field value $lt (less than) 30
What is this query doing?
Insert some real data on people
What is this query doing?
Find people whose age is below 30
How do you use MQL find?
What is insertOne(), insertMany(), writeConcern and ordered?
- insertOne() = insert one document into a collection
- insertMany() = insert an array of documents into a collection
- writeConcern = sets the level of acknowledgement requested from MongoDB for write operations
- ordered = for insertMany() there is an additional option for controlling whether the documents are inserted in ordered or unordered fashion
Give an example using insertOne(), insertMany(), writeConcern and ordered
What is updateOne() and updateMany()?
- updateOne() = update one document into a collection
- updateMany() = update an array of documents into a collection
Give an example using updateOne() and updateMany()
What is deleteOne(), deleteMany() and writeConcern?
- deleteOne() = deletes one document from a collection
- deleteMany() = deletes many documents from a collection
- writeConcern = sets the level of acknowledgement requested from MongoDB for write operations
Give an example using deleteOne(), deleteMany() and writeConcern
What are some MQL query operator comparisons and what they do?
- $lt = exists and less than
- $lte = exists and less than or equal to
- $gt = exists and greater than
- $gte = exists and greater than or equal to
- $ne = does not exist or does not equal to
- $eq = exists and equal to
- $in = exists and in a set
- $nin = does not exists or not in a set
- $or = match either of two or more values
- $not = used with other operators to negate
- $nor = match neither of two or more values
- $and = match both of two or more values