MongoDB Multiple Choice Questions
Test your MongoDB knowledge with these comprehensive multiple-choice questions. Hover over any question to reveal the correct answer.
Jump to Section:
1. Introduction to MongoDB
1. MongoDB is classified as what type of database?
Easy
Answer: B. Document Database
2. What is the basic unit of data in MongoDB?
Easy
Answer: B. Document
3. MongoDB stores data in which format?
Medium
Answer: C. BSON (Binary JSON)
4. Which of these is NOT a feature of MongoDB?
Medium
Answer: C. Joins between collections (MongoDB doesn't support traditional joins)
5. What is the equivalent of a table in relational databases in MongoDB?
Hard
Answer: C. Collection
2. Setting Up MongoDB Environment
6. Which command starts the MongoDB shell?
Easy
Answer: B. mongo
7. Which of these is NOT a MongoDB GUI tool?
Easy
Answer: D. MySQL Workbench
8. What is the default port for MongoDB server?
Medium
Answer: A. 27017
9. Which command displays version information in MongoDB shell?
Medium
Answer: A. db.version()
10. What does the mongod command do?
Hard
Answer: B. Starts the MongoDB server
3. Basic Operations
11. Which command creates a new database in MongoDB?
Easy
Answer: C. use database_name (MongoDB creates databases implicitly when you first store data)
12. How do you list all databases in MongoDB?
Easy
Answer: C. show dbs
13. Which command creates a new collection?
Medium
Answer: D. Both B and C (Collections are created implicitly when data is inserted)
14. What does the drop() method do in MongoDB?
Medium
Answer: D. Both B and C (db.collection.drop() or db.dropDatabase())
15. How do you display the current database in MongoDB shell?
Hard
Answer: B. db.getName()
4. CRUD Operations
16. Which method inserts documents into a collection?
Easy
Answer: B. db.collection.insert() (also insertOne() or insertMany())
17. Which method updates existing documents?
Easy
Answer: B. db.collection.update() (also updateOne() or updateMany())
18. Which method removes documents from a collection?
Medium
Answer: A. db.collection.remove() (also deleteOne() or deleteMany())
19. What is the difference between update() and save() methods?
Medium
Answer: B. save() can insert or update based on _id
20. Which operator is used to set fields in an update operation?
Hard
Answer: B. $set
5. Querying Data
21. Which method retrieves documents from a collection?
Easy
Answer: C. db.collection.find()
22. Which operator is used for equality matching in queries?
Easy
Answer: A. $eq (though simple field:value syntax is more common)
23. Which operator is used for "greater than" comparisons?
Medium
Answer: A. $gt
24. What does the $in operator do?
Medium
Answer: D. Checks if a value is in a specified list
25. Which method limits the number of documents returned?
Hard
Answer: A. limit()
6. Indexes
26. Which method creates an index in MongoDB?
Easy
Answer: B. db.collection.createIndex()
27. What is the default index created by MongoDB?
Easy
Answer: B. _id index
28. Which index type supports geospatial queries?
Medium
Answer: C. 2dsphere
29. What is a covered query?
Medium
Answer: B. A query that returns only indexed fields
30. Which method lists all indexes on a collection?
Hard
Answer: A. db.collection.getIndexes()
7. Aggregation Framework
31. Which method performs aggregation operations?
Medium
Answer: B. db.collection.aggregate()
32. Which aggregation stage filters documents?
Medium
Answer: C. $match
33. Which aggregation stage groups documents by expression?
Easy
Answer: A. $group
34. Which operator calculates the average in $group stage?
Medium
Answer: A. $avg
35. Which stage limits the number of documents passed to next stage?
Hard
Answer: C. $limit
8. Replication
36. What is a replica set in MongoDB?
Medium
Answer: B. A group of mongod instances with the same data
37. What is the minimum number of nodes in a replica set?
Medium
Answer: C. 3 (1 primary and 2 secondaries recommended for production)
38. Which node accepts all write operations in a replica set?
Easy
Answer: A. Primary
39. What is the purpose of an arbiter in a replica set?
Medium
Answer: B. To break election ties
40. Which command initializes a replica set?
Hard
Answer: A. rs.initiate()
9. Sharding
41. What is sharding in MongoDB?
Medium
Answer: B. A method for horizontal scaling
42. Which component routes queries to the correct shard?
Medium
Answer: B. mongos (the query router)
43. What is a shard key?
Easy
Answer: B. A field used to distribute data across shards
44. Which sharding strategy divides data into contiguous ranges?
Medium
Answer: B. Range sharding
45. Which command enables sharding for a database?
Hard
Answer: A. sh.enableSharding()
10. Security
46. Which authentication mechanism is recommended for MongoDB?
Medium
Answer: B. SCRAM-SHA-256 (default since MongoDB 4.0)
47. Which role provides full administrative access?
Easy
Answer: B. root
48. Which command creates a new user?
Medium
Answer: B. db.createUser()
49. What is TLS/SSL used for in MongoDB?
Medium
Answer: B. Encrypting client-server communications
50. Which feature provides field-level encryption?
Hard
Answer: B. Client-Side Field Level Encryption
11. Performance
51. Which method explains query execution?
Easy
Answer: A. db.collection.explain()
52. Which tool monitors MongoDB performance?
Easy
Answer: D. All of the above
53. Which index type supports text search?
Medium
Answer: C. Text
54. What is covered by the profiler in MongoDB?
Medium
Answer: D. Configurable based on profiling level
55. Which command flushes all pending writes to disk?
Hard
Answer: C. db.runCommand({fsync: 1})
12. Transactions
56. Since which version does MongoDB support multi-document ACID transactions?
Medium
Answer: C. 4.0 (for replica sets, 4.2 added sharded cluster support)
57. Which method starts a transaction in MongoDB?
Medium
Answer: A. session.startTransaction()
58. Which method commits a transaction?
Easy
Answer: B. session.commitTransaction()
59. What is the default transaction timeout in MongoDB?
Medium
Answer: B. 60 seconds
60. Which method aborts a transaction?
Easy
Answer: B. session.abortTransaction()