General Flashcards
What is MongoDB?
MongoDB is a NoSQL database program that uses JSON-like documents with optional schemas.
What is a NoSQL database?
A NoSQL database provides a mechanism for storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases.
How does MongoDB store data?
MongoDB stores data in flexible, JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time.
What is a collection in MongoDB?
A collection is a group of MongoDB documents. It is the equivalent of an RDBMS table, but it doesn’t enforce any structure.
What is a document in MongoDB?
A document is a record in a MongoDB collection, similar to a row in a table of an RDBMS.
What is the purpose of BSON in MongoDB?
BSON (Binary JSON) is a binary-encoded serialization of JSON-like documents. It supports more data types than JSON.
How does MongoDB handle indexing?
MongoDB supports various types of indexes including single field, compound, multikey, geospatial, text, hashed, clustered (>= v5.3) indexes.
What is sharding in MongoDB?
Sharding is the process of storing data records across multiple machines to ensure horizontal scalability.
What is replication in MongoDB?
Replication is the process of synchronizing data across multiple servers to provide redundancy and high availability.
What is a replica set in MongoDB?
A replica set is a group of MongoDB instances that maintain the same data set, providing redundancy and high availability.
What are the advantages of using MongoDB over relational databases?
Advantages include a flexible schema design, easier scalability, high performance for certain types of workloads, and simpler management of large datasets.
What are the disadvantages of MongoDB?
Disadvantages include the potential for increased complexity in certain scenarios, less mature tooling compared to relational databases, and specific use cases where relational databases might be more efficient.
What is the Aggregation Framework in MongoDB?
The Aggregation Framework is a set of operations that process data records and return computed results. It provides a way to transform and combine data.
What is a primary key in MongoDB?
In MongoDB, the primary key is automatically set to the _id field in each document. Each document’s _id must be unique within a collection.
How does MongoDB ensure ACID transactions?
MongoDB ensures ACID transactions at the document level and, starting with version 4.0, it supports multi-document transactions to provide atomicity, consistency, isolation, and durability across multiple documents.
What are some common use cases for MongoDB?
Common use cases include content management, real-time analytics, Internet of Things (IoT) applications, mobile applications, and catalog management.
What is the difference between MongoDB and MySQL?
MongoDB is a NoSQL, document-oriented database, while MySQL is a relational database management system (RDBMS). MongoDB uses JSON-like documents, whereas MySQL uses structured tables and rows.
What is the role of the _id field in MongoDB?
The _id field in MongoDB serves as the primary key for a document in a collection. It uniquely identifies each document and is required in every document.
How can you create a new database in MongoDB?
In MongoDB, a new database is created when you first store data in that database. You can switch to a new database using the use command, followed by the name of the database.
What is a capped collection in MongoDB?
A capped collection is a fixed-size collection that maintains insertion order and, once the specified size limit is reached, overwrites the oldest documents.
What is GridFS in MongoDB?
GridFS is a specification for storing and retrieving large files, such as images, videos, and documents, in MongoDB. It splits files into smaller chunks and stores each chunk as a separate document.
How does MongoDB handle concurrency?
MongoDB uses a combination of multi-granularity locking, including reader-writer locks at the database, collection, and document levels, to manage concurrency.
What is a MongoDB query language (MQL)?
MongoDB Query Language (MQL) is the language used to interact with MongoDB, allowing users to perform CRUD operations, query documents, and interact with the database.
How do you update a document in MongoDB?
To update a document in MongoDB, you use the updateOne, updateMany, or replaceOne methods, specifying the criteria for the document(s) to update and the new values.