Document Databases (MongoDB, Couchbase) Flashcards
MongoDB overview and document model BSON format Collections vs Tables Schema design in MongoDB CRUD operations using find, insertOne, updateOne, deleteOne Querying nested fields and arrays Indexes in MongoDB Aggregation pipeline Transactions in MongoDB Replication and sharding in MongoDB (35 cards)
What is MongoDB?
MongoDB is a NoSQL, document-oriented database that stores data in flexible, JSON-like documents.
What is the document model in MongoDB?
The document model stores data as BSON documents which can include nested fields and arrays, allowing for more natural data modeling.
What is BSON in MongoDB?
BSON (Binary JSON) is a binary format used to store documents in MongoDB, supporting additional data types like Date and BinData.
How do MongoDB collections compare to relational database tables?
Collections are analogous to tables, but they do not enforce a schema, allowing documents with different structures in the same collection.
What is schema design in MongoDB?
Schema design in MongoDB involves structuring documents and collections to optimize for queries, updates, and scaling.
What is the purpose of insertOne in MongoDB?
insertOne
is a CRUD operation that adds a single document to a collection.
What does find do in MongoDB?
find
retrieves documents from a collection that match specified query criteria.
What does updateOne do in MongoDB?
updateOne
modifies the first document that matches the filter criteria in a collection.
What does deleteOne do in MongoDB?
deleteOne
removes the first document that matches the filter criteria from a collection.
How do you query nested fields in MongoDB?
Use dot notation, like find({ 'address.city': 'New York' })
, to query nested fields.
How do you query arrays in MongoDB?
You can use operators like $elemMatch
or $in
to query array fields.
What are indexes in MongoDB?
Indexes improve query performance by allowing efficient data retrieval without scanning all documents.
What types of indexes does MongoDB support?
MongoDB supports single-field, compound, multikey, geospatial, text, and hashed indexes.
What is the aggregation pipeline in MongoDB?
A framework that processes documents through multiple stages like $match
, $group
, $project
, etc., to transform and analyze data.
What is the purpose of transactions in MongoDB?
Transactions ensure that multiple operations across multiple documents execute as a single atomic unit, preserving data integrity.
What is replication in MongoDB?
Replication copies data from a primary node to secondary nodes, ensuring high availability and data redundancy.
What is sharding in MongoDB?
Sharding distributes data across multiple machines (shards) to support horizontal scaling of large datasets.
What are document databases?
Document databases store data in document format (JSON, BSON, XML), and each document is a self-contained unit of data.
What are examples of document databases?
Examples include MongoDB, Couchbase, and Amazon DocumentDB.
What are the advantages of document databases?
Advantages include flexible schema, faster development, natural data modeling, and easier horizontal scaling.
What are the disadvantages of document databases?
Disadvantages include data duplication, limited support for complex joins, and higher memory usage.
What are best practices for MongoDB schema design?
Model around application query patterns, embed related data when access is frequent, avoid deeply nested documents, and use proper indexing.
When should you embed documents in MongoDB?
Embed when the relationship is one-to-few and data is accessed together, like a user and their addresses.
When should you reference documents in MongoDB?
Reference when the relationship is one-to-many or many-to-many and data is accessed independently.