MongoDB QnAs for Vivavoce
What is MongoDB, and why is it called a NoSQL database?
- MongoDB is a document-oriented NoSQL database that stores data in JSON-like documents. It is called NoSQL because it does not use traditional SQL (Structured Query Language) for querying data.
What is a document in MongoDB?
- A document in MongoDB is a JSON-like object that contains key-value pairs and is the basic unit of data storage.
Explain the structure of a MongoDB document.
- A MongoDB document consists of fields, which are key-value pairs, and it can have nested documents and arrays.
What is a collection in MongoDB?
- A collection in MongoDB is a group of MongoDB documents. It is similar to a table in a relational database.
How do you insert a document into a MongoDB collection?
- You can insert a document into a collection using the
insertOne()
orinsertMany()
method.
- You can insert a document into a collection using the
Explain the concept of ObjectId in MongoDB.
- ObjectId is a 12-byte identifier that is unique within a collection and is automatically generated for each document. It consists of a timestamp, machine ID, and more.
What is indexing in MongoDB, and why is it important?
- Indexing in MongoDB is the process of creating a data structure to improve the speed of data retrieval operations on a database. It is important for optimizing query performance.
What is the primary key in MongoDB?
- In MongoDB, the primary key is the
_id
field, which uniquely identifies each document in a collection.
- In MongoDB, the primary key is the
Explain the difference between a replica set and a sharded cluster in MongoDB.
- A replica set is a group of MongoDB servers that maintain the same data for redundancy and high availability. A sharded cluster, on the other hand, is used for horizontal scaling and distributing data across multiple servers.
What is the purpose of the MongoDB aggregation framework?
- The aggregation framework in MongoDB is used for data transformation, filtering, and computation of data. It allows for complex data processing tasks.
How do you perform a query in MongoDB to retrieve documents that match certain criteria?
- You can use the
find()
method to perform queries in MongoDB. For example,db.collection.find({ field: value })
.
- You can use the
What is the
$set
operator used for in MongoDB?- The
$set
operator is used to update specific fields within a document without affecting other fields.
- The
Explain the difference between a NoSQL database like MongoDB and a traditional relational database.
- NoSQL databases like MongoDB are schema-less, whereas relational databases have a fixed schema. NoSQL databases are suitable for unstructured data, while relational databases are ideal for structured data.
What is sharding in MongoDB, and when should you consider using it?
- Sharding is the process of distributing data across multiple servers to improve scalability and performance. It should be considered when a single server can't handle the data and traffic volume.
How do you ensure data consistency in a replica set in MongoDB?
- Data consistency is maintained in a replica set through automatic failover. When the primary node goes down, one of the secondary nodes is automatically elected as the new primary.
What is the purpose of the
mongod
process in MongoDB?- The
mongod
process is the primary daemon process for MongoDB, responsible for managing the database server.
- The
What is the WiredTiger storage engine in MongoDB, and why is it widely used?
- WiredTiger is the default storage engine in MongoDB, known for its high performance and data compression capabilities. It's widely used for improved efficiency.
Explain the concept of "write concern" in MongoDB.
- Write concern in MongoDB determines the acknowledgment level that a write operation must achieve to be considered successful. It can be set to "acknowledged," "journaled," or "majority," among other options.
What is the purpose of the MongoDB Atlas service?
- MongoDB Atlas is a cloud-based database service provided by MongoDB for managing and hosting MongoDB databases in the cloud.
How do you back up and restore data in MongoDB?
- You can back up data in MongoDB using tools like
mongodump
, and you can restore data usingmongorestore
. These tools work with binary BSON data.
- You can back up data in MongoDB using tools like
Comments
Post a Comment