1. Question: What is MongoDB, and how does it differ from traditional relational databases?
- Answer: MongoDB
is a NoSQL document-oriented database. Unlike traditional relational databases,
MongoDB stores data in flexible, JSON-like BSON documents and does not require
a predefined schema.
2. Question: What is a BSON in MongoDB?
- Answer: BSON
(Binary JSON) is a binary-encoded serialization of JSON-like documents used in
MongoDB. It supports additional data types, such as Date and Binary, compared
to standard JSON.
3. Question: Explain the concept of a document in MongoDB.
- Answer: In
MongoDB, a document is a basic unit of data, similar to a row in a relational
database. It is a JSON-like data structure that can contain various types of
data, including nested documents and arrays.
4. Question: What is the purpose of an ObjectId in MongoDB?
- Answer: ObjectId
is a 12-byte identifier unique within a MongoDB instance. It is automatically
generated and serves as the default primary key for documents, ensuring
uniqueness.
5. Question: How does MongoDB ensure high availability and
fault tolerance?
- Answer: MongoDB
achieves high availability through features like replica sets. A replica set
consists of multiple nodes, and if one node fails, another can take over,
ensuring continuous operation.
6. Question: What is the role of the `_id` field in MongoDB
documents?
- Answer: The `_id`
field in MongoDB documents uniquely identifies each document in a collection.
If not specified during document creation, MongoDB automatically assigns a
unique ObjectId.
7. Question: Explain the difference between MongoDB sharding
and replication.
- Answer: Sharding
involves distributing data across multiple machines to improve scalability,
while replication involves creating copies of data on multiple servers to
enhance fault tolerance and availability.
8. Question: How does indexing work in MongoDB, and why is
it important?
- Answer: MongoDB
supports indexes to improve query performance. Indexes are created on fields,
and they facilitate faster data retrieval by allowing MongoDB to locate and
access data more efficiently.
9. Question: What is the aggregation framework in MongoDB?
- Answer: The
aggregation framework is a powerful tool in MongoDB for data transformation and
analysis. It provides a set of operators to filter, group, project, and perform
various transformations on data.
10. Question: What is the purpose of the `find()` method in
MongoDB?
- Answer: The
`find()` method is used to query documents in a MongoDB collection. It allows
specifying query criteria, projection, sorting, and other options to retrieve
matching documents.
11. Question: Explain the concept of a MongoDB Atlas.
- Answer: MongoDB
Atlas is a fully managed cloud database service provided by MongoDB. It offers
features like automated backups, monitoring, and scaling, making it easy to
deploy and manage MongoDB in the cloud.
12. Question: How does MongoDB handle transactions, and what
is a two-phase commit?
- Answer: MongoDB
supports multi-document transactions starting from version 4.0. A two-phase
commit is a protocol used to ensure atomicity across multiple distributed nodes
during a transaction.
13. Question: What is the role of the `mongod` process in
MongoDB?
- Answer: The
`mongod` process is the MongoDB server daemon responsible for managing database
operations. It handles requests from clients, performs data storage and
retrieval, and manages data integrity.
14. Question: How does MongoDB handle schema evolution?
- Answer:
MongoDB's flexible schema allows for dynamic changes to documents without a
predefined schema. Fields can be added or modified without affecting existing
documents.
15. Question: What is a capped collection in MongoDB?
- Answer: A capped
collection in MongoDB is a fixed-size collection where older data is
automatically replaced by newer data when the collection reaches its maximum
size. It is often used for logs or other time-series data.
16. Question: Explain the role of the
`db.collection.createIndex()` method in MongoDB.
- Answer: The
`db.collection.createIndex()` method is used to create indexes on specific
fields in a collection. Indexes improve query performance by allowing MongoDB
to quickly locate and access data.
17. Question: What is the purpose of the `mongorestore`
command in MongoDB?
- Answer: The
`mongorestore` command is used to restore data previously created with
`mongodump`. It imports BSON data into a MongoDB instance, recreating the data
from a backup.
18. Question: How does MongoDB handle concurrency control
and locking?
- Answer: MongoDB
uses a reader-writer lock to manage concurrency. Multiple readers can access
data simultaneously, but write operations lock the database to ensure
consistency.
19. Question: What is the role of the WiredTiger storage
engine in MongoDB?
- Answer:
WiredTiger is the default storage engine in MongoDB from version 3.2 onward. It
provides features like compression, document-level concurrency control, and
efficient storage.
20. Question: How can you secure a MongoDB database?
- Answer: MongoDB
security measures include authentication, authorization, encryption of data in
transit and at rest, role-based access control, and regular security audits.
Additionally, firewalls and network security play crucial roles in securing
MongoDB deployments.
No comments:
Post a Comment