0% found this document useful (0 votes)
6 views

MongoDB Interview Questions Answers Yogesh Sabale

The document provides an overview of MongoDB, a NoSQL database that uses JSON-like BSON documents, highlighting its key features such as schema-less design, scalability, and high performance. It includes common interview questions and answers regarding database creation, data manipulation, indexing, and security practices. Additionally, it explains the differences between MongoDB and MySQL, as well as how MongoDB handles relationships and large-scale applications.

Uploaded by

Yogesh Sabale
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

MongoDB Interview Questions Answers Yogesh Sabale

The document provides an overview of MongoDB, a NoSQL database that uses JSON-like BSON documents, highlighting its key features such as schema-less design, scalability, and high performance. It includes common interview questions and answers regarding database creation, data manipulation, indexing, and security practices. Additionally, it explains the differences between MongoDB and MySQL, as well as how MongoDB handles relationships and large-scale applications.

Uploaded by

Yogesh Sabale
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

MongoDB Interview Questions & Answers - Yogesh Punaji Sabale

What is MongoDB, and why is it used?


MongoDB is a NoSQL database that stores data in JSON-like BSON documents instead of tables. It
is schema-less, highly scalable, and optimized for high-speed data retrieval.

What are the key features of MongoDB?


Schema-less, Document-Oriented, Scalability with Sharding, High Performance with Indexing.

How does MongoDB differ from MySQL?


MongoDB is NoSQL (document-based), while MySQL is relational (table-based). MongoDB is
schema-less and scalable horizontally, while MySQL uses structured schema and scales vertically.

How do you create a database in MongoDB?


use myDatabase (Creates a new database when a collection is added).

How do you create a collection in MongoDB?


db.createCollection('users')

How do you insert a document into MongoDB?


db.users.insertOne({ name: 'John Doe', age: 25, email: '[email protected]' })

How do you retrieve data from MongoDB?


db.users.find() (Retrieves all documents).

How do you update data in MongoDB?


db.users.updateOne({ name: 'John Doe' }, { $set: { age: 26 } })

How do you delete data from MongoDB?


db.users.deleteOne({ name: 'John Doe' })

What is indexing in MongoDB, and why is it important?


Indexing improves query speed by allowing faster data retrieval. Example: db.users.createIndex({
email: 1 })

What types of indexes are available in MongoDB?


Single Field Index, Compound Index, Text Index, Geospatial Index.

How do you optimize queries in MongoDB?


Use indexes, avoid unnecessary find() queries, use projection, and leverage the aggregation
framework.
What is the aggregation framework in MongoDB?
Aggregation is used to process and transform data in multiple stages, similar to SQL's GROUP BY.

How do you use the aggregation pipeline?


db.users.aggregate([{ $match: { age: { $gte: 18 } } }, { $group: { _id: '$age', total: { $sum: 1 } } }])

How does MongoDB handle relationships between documents?


MongoDB uses Embedding (stores related data inside a document) and Referencing (stores
references to related documents).

What is the difference between embedding and referencing in MongoDB?


Embedding stores all data in one document, making reads faster. Referencing uses separate
documents linked by ObjectId, saving space.

How do you secure MongoDB databases?


Enable authentication, use TLS/SSL encryption, and limit user privileges with roles.

How do you back up a MongoDB database?


Use the mongodump command: mongodump --db myDatabase --out /backup/

How does MongoDB handle large-scale applications?


MongoDB uses sharding to distribute data across multiple servers and replication for data
redundancy.

Why did you choose MongoDB for backend development?


MongoDB is flexible, scalable, and efficient for handling large datasets. It supports fast reads and
writes, making it ideal for modern web applications.

You might also like