MCQs on Advanced Query and Index Optimization | MongoDB MCQs

MongoDB offers powerful features for advanced query and index optimization, enhancing database performance. Developers can utilize geospatial queries for location-based data, full-text search for fast text retrieval, TTL indexes for automated data expiration, and performance tuning techniques for scalability. This quiz explores these advanced concepts to boost your MongoDB expertise.


Geospatial Queries

Q1. What type of index is required to perform geospatial queries in MongoDB?

a) Compound Index
b) Geospatial Index
c) Text Index
d) TTL Index

Q2. Which operator is used to find documents within a specific geometry?

a) $within
b) $geoWithin
c) $contains
d) $geoMatch

Q3. The $near operator in geospatial queries is used to:

a) Match documents by exact coordinates
b) Sort documents by distance from a point
c) Check if a field exists
d) Perform full-text search

Q4. In MongoDB, geospatial data is represented using:

a) Arrays of points
b) JSON strings
c) Binary objects
d) Tables

Q5. Which of the following is NOT a valid geospatial index type in MongoDB?

a) 2d Index
b) 2dsphere Index
c) Polygon Index
d) None of the above


Full-Text Search Queries

Q6. What type of index is required for full-text search in MongoDB?

a) Compound Index
b) Full-text Index
c) Text Index
d) Unique Index

Q7. Which command is used to perform a full-text search in MongoDB?

a) db.collection.textSearch()
b) db.collection.search()
c) $text
d) $findText

Q8. In a full-text search query, the $text operator requires which field to be included?

a) $search
b) $index
c) $match
d) $contains

Q9. What does the $language field specify in a text search query?

a) The text encoding format
b) The natural language for stemming and tokenization
c) The character limit for the text
d) The index size

Q10. How do you assign a custom score to search results in MongoDB text search?

a) Using $sort
b) Using $meta
c) Using $rank
d) Using $priority


TTL (Time-to-Live) Indexes

Q11. What is the primary use of TTL indexes in MongoDB?

a) Archiving documents
b) Automatically deleting expired documents
c) Improving query performance
d) Optimizing storage

Q12. TTL indexes are set on which type of field?

a) Numeric fields
b) String fields
c) Date fields
d) ObjectId fields

Q13. What is the minimum granularity of TTL expiration in MongoDB?

a) 1 second
b) 1 millisecond
c) 1 minute
d) 1 hour

Q14. How is the expiration time defined for a document in a TTL index?

a) By the _id field
b) Using a specific TTL field
c) Through a Unix timestamp field
d) Using the index creation command

Q15. What happens when the expiration time of a TTL-indexed document is reached?

a) The document is archived
b) The document is deleted automatically
c) An error is thrown
d) The index is dropped


Performance Tuning Techniques

Q16. What is the purpose of using explain() in MongoDB?

a) To execute a query faster
b) To analyze query performance and execution plan
c) To create indexes
d) To delete unnecessary data

Q17. Which parameter can be used to limit memory usage for MongoDB queries?

a) queryOptimizer
b) allowDiskUse
c) memoryLimit
d) maxQueryMem

Q18. How does sharding improve MongoDB performance?

a) By reducing the document size
b) By distributing data across multiple nodes
c) By compressing indexes
d) By archiving old data

Q19. What is the impact of using compound indexes?

a) Improves query performance for specific use cases
b) Reduces storage requirements
c) Slows down write operations
d) Prevents duplicate entries

Q20. Which of the following can improve write performance in MongoDB?

a) Increasing index size
b) Using smaller document sizes
c) Reducing memory usage
d) Limiting the number of shards

Q21. How can you monitor database performance in MongoDB?

a) Using db.performanceCheck()
b) Through MongoDB Compass or Monitoring Tools
c) By writing custom scripts
d) Through server logs

Q22. Which option ensures atomic operations in MongoDB?

a) Using transactions
b) Using queries
c) By creating unique indexes
d) By sharding collections

Q23. What does the WiredTiger engine optimize in MongoDB?

a) CPU performance
b) Disk I/O and concurrency
c) Memory usage
d) Backup speeds

Q24. Which tool can analyze MongoDB logs for query performance?

a) mongo-analyze
b) profiler
c) mongotop
d) logParser

Q25. Which is NOT a recommended strategy for performance tuning in MongoDB?

a) Reducing index usage
b) Indexing frequently queried fields
c) Analyzing slow queries
d) Using sharding for large datasets


Answer Key

QNoAnswer
1b) Geospatial Index
2b) $geoWithin
3b) Sort documents by distance from a point
4a) Arrays of points
5c) Polygon Index
6c) Text Index
7c) $text
8a) $search
9b) The natural language for stemming and tokenization
10b) Using $meta
11b) Automatically deleting expired documents
12c) Date fields
13c) 1 minute
14c) Through a Unix timestamp field
15b) The document is deleted automatically
16b) To analyze query performance and execution plan
17b) allowDiskUse
18b) By distributing data across multiple nodes
19a) Improves query performance for specific use cases
20b) Using smaller document sizes
21b) Through MongoDB Compass or Monitoring Tools
22a) Using transactions
23b) Disk I/O and concurrency
24c) mongotop
25a) Reducing index usage

4o

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top