MongoDB MCQs – Performance Optimization

11.) What is the recommended way to avoid performance issues with $or queries?

A) Use $and instead of $or
B) Optimize indexes for each condition
C) Avoid combining conditions
D) Always use aggregation pipelines

Answer: Option B

Explanation: Creating indexes for fields used in $or queries improves their performance.

12.) Which tool is used to visualize MongoDB performance metrics?

A) MongoDB Compass
B) db.collection.analyze()
C) mongotop
D) mongostat

Answer: Option A

Explanation: MongoDB Compass provides a graphical interface for monitoring and analyzing database performance metrics.

13.) What does the “working set” in MongoDB refer to?

A) The set of active indexes
B) The data frequently accessed by the database
C) The documents processed by a query
D) The memory allocated for aggregation

Answer: Option B

Explanation: The working set refers to the subset of data that is frequently accessed and ideally fits in memory for optimal performance.

14.) What is the purpose of the $limit stage in the aggregation pipeline?

A) Filters documents based on conditions
B) Groups documents by a field
C) Joins two collections
D) Restricts the number of documents processed

Answer: Option D

Explanation: The $limit stage reduces the number of documents passed to subsequent stages, improving query performance.

15.) How can sharding improve MongoDB performance?

A) By increasing document size limits
B) By distributing data across multiple servers
C) By reducing index usage
D) By disabling replication

Answer: Option B

Explanation: Sharding distributes data across servers, improving read and write performance for large datasets.

16.) Which command analyzes replication performance in MongoDB?

A) mongotop
B) mongostat
C) db.printReplicationInfo()
D) db.replicaSet.stats()

Answer: Option C

Explanation: The printReplicationInfo() command provides details about replication status and performance.

17.) Which MongoDB feature prevents large write operations from overwhelming the database?

A) Query profiler
B) Write concern
C) Read preference
D) Capped collections

Answer: Option B

Explanation: Write concern ensures the database handles write operations safely, preventing performance bottlenecks.

18.) What is the purpose of secondary indexes?

A) To speed up specific queries
B) To improve write performance
C) To manage sharding configurations
D) To reduce document size

Answer: Option A

Explanation: Secondary indexes optimize query performance for non-primary fields.

19.) Which storage option ensures faster reads for frequently accessed data?

A) Disk-based storage
B) Distributed storage
C) Compressed storage
D) In-memory storage

Answer: Option D

Explanation: In-memory storage keeps frequently accessed data in memory, reducing latency for read operations.

20.) How does MongoDB ensure write durability?

A) Using query profiling
B) By enabling journaling
C) By sharding data
D) By creating multiple indexes

Answer: Option B

Explanation: Journaling ensures write durability by recording changes before committing them to the database.

Leave a Reply

Your email address will not be published. Required fields are marked *