MongoDB Multiple Choice Questions

Test your MongoDB knowledge with these comprehensive multiple-choice questions. Hover over any question to reveal the correct answer.

1. Introduction to MongoDB

1. MongoDB is classified as what type of database? Easy
A. Relational Database
B. Document Database
C. Key-Value Store
D. Graph Database
Answer: B. Document Database
2. What is the basic unit of data in MongoDB? Easy
A. Table
B. Document
C. Row
D. Collection
Answer: B. Document
3. MongoDB stores data in which format? Medium
A. XML
B. JSON
C. BSON
D. CSV
Answer: C. BSON (Binary JSON)
4. Which of these is NOT a feature of MongoDB? Medium
A. Schema-less design
B. Horizontal scaling
C. Joins between collections
D. Full-text search
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
A. Document
B. Field
C. Collection
D. Database
Answer: C. Collection

2. Setting Up MongoDB Environment

6. Which command starts the MongoDB shell? Easy
A. mongod
B. mongo
C. start mongodb
D. mongoshell
Answer: B. mongo
7. Which of these is NOT a MongoDB GUI tool? Easy
A. MongoDB Compass
B. Robo 3T
C. Studio 3T
D. MySQL Workbench
Answer: D. MySQL Workbench
8. What is the default port for MongoDB server? Medium
A. 27017
B. 3306
C. 5432
D. 8080
Answer: A. 27017
9. Which command displays version information in MongoDB shell? Medium
A. db.version()
B. version()
C. mongod --version
D. db.serverStatus().version
Answer: A. db.version()
10. What does the mongod command do? Hard
A. Starts the MongoDB shell
B. Starts the MongoDB server
C. Imports data into MongoDB
D. Exports data from MongoDB
Answer: B. Starts the MongoDB server

3. Basic Operations

11. Which command creates a new database in MongoDB? Easy
A. CREATE DATABASE
B. db.createDatabase()
C. use database_name
D. db.newDatabase()
Answer: C. use database_name (MongoDB creates databases implicitly when you first store data)
12. How do you list all databases in MongoDB? Easy
A. SHOW DATABASES
B. db.listDatabases()
C. show dbs
D. db.adminCommand({listDatabases: 1})
Answer: C. show dbs
13. Which command creates a new collection? Medium
A. CREATE COLLECTION
B. db.createCollection()
C. db.collection.insert()
D. Both B and C
Answer: D. Both B and C (Collections are created implicitly when data is inserted)
14. What does the drop() method do in MongoDB? Medium
A. Deletes a document
B. Deletes a collection
C. Deletes a database
D. Both B and C
Answer: D. Both B and C (db.collection.drop() or db.dropDatabase())
15. How do you display the current database in MongoDB shell? Hard
A. db.currentDatabase()
B. db.getName()
C. show current
D. db
Answer: B. db.getName()

4. CRUD Operations

16. Which method inserts documents into a collection? Easy
A. db.collection.add()
B. db.collection.insert()
C. db.collection.create()
D. db.collection.new()
Answer: B. db.collection.insert() (also insertOne() or insertMany())
17. Which method updates existing documents? Easy
A. db.collection.modify()
B. db.collection.update()
C. db.collection.change()
D. db.collection.alter()
Answer: B. db.collection.update() (also updateOne() or updateMany())
18. Which method removes documents from a collection? Medium
A. db.collection.remove()
B. db.collection.delete()
C. db.collection.drop()
D. db.collection.erase()
Answer: A. db.collection.remove() (also deleteOne() or deleteMany())
19. What is the difference between update() and save() methods? Medium
A. update() modifies existing docs, save() inserts new docs
B. save() can insert or update based on _id
C. update() is faster than save()
D. save() is deprecated
Answer: B. save() can insert or update based on _id
20. Which operator is used to set fields in an update operation? Hard
A. $put
B. $set
C. $add
D. $update
Answer: B. $set

5. Querying Data

21. Which method retrieves documents from a collection? Easy
A. db.collection.get()
B. db.collection.retrieve()
C. db.collection.find()
D. db.collection.fetch()
Answer: C. db.collection.find()
22. Which operator is used for equality matching in queries? Easy
A. $eq
B. ==
C. =
D. All of the above
Answer: A. $eq (though simple field:value syntax is more common)
23. Which operator is used for "greater than" comparisons? Medium
A. $gt
B. >
C. $greater
D. $more
Answer: A. $gt
24. What does the $in operator do? Medium
A. Checks if a value is in an array
B. Checks if a field exists
C. Performs case-insensitive search
D. Checks if a value is in a specified list
Answer: D. Checks if a value is in a specified list
25. Which method limits the number of documents returned? Hard
A. limit()
B. top()
C. size()
D. max()
Answer: A. limit()

6. Indexes

26. Which method creates an index in MongoDB? Easy
A. db.collection.addIndex()
B. db.collection.createIndex()
C. db.collection.makeIndex()
D. db.collection.newIndex()
Answer: B. db.collection.createIndex()
27. What is the default index created by MongoDB? Easy
A. Primary index
B. _id index
C. Clustered index
D. No default index
Answer: B. _id index
28. Which index type supports geospatial queries? Medium
A. Single field
B. Compound
C. 2dsphere
D. Text
Answer: C. 2dsphere
29. What is a covered query? Medium
A. A query that uses an index
B. A query that returns only indexed fields
C. A query with multiple conditions
D. A query that spans multiple collections
Answer: B. A query that returns only indexed fields
30. Which method lists all indexes on a collection? Hard
A. db.collection.getIndexes()
B. show indexes
C. db.collection.indexes()
D. db.collection.listIndexes()
Answer: A. db.collection.getIndexes()

7. Aggregation Framework

31. Which method performs aggregation operations? Medium
A. db.collection.group()
B. db.collection.aggregate()
C. db.collection.summarize()
D. db.collection.process()
Answer: B. db.collection.aggregate()
32. Which aggregation stage filters documents? Medium
A. $where
B. $filter
C. $match
D. $select
Answer: C. $match
33. Which aggregation stage groups documents by expression? Easy
A. $group
B. $summarize
C. $cluster
D. $collect
Answer: A. $group
34. Which operator calculates the average in $group stage? Medium
A. $avg
B. $mean
C. $average
D. $arithmeticMean
Answer: A. $avg
35. Which stage limits the number of documents passed to next stage? Hard
A. $restrict
B. $sample
C. $limit
D. $top
Answer: C. $limit

8. Replication

36. What is a replica set in MongoDB? Medium
A. A set of identical databases
B. A group of mongod instances with the same data
C. A collection of similar documents
D. A backup strategy
Answer: B. A group of mongod instances with the same data
37. What is the minimum number of nodes in a replica set? Medium
A. 1
B. 2
C. 3
D. 5
Answer: C. 3 (1 primary and 2 secondaries recommended for production)
38. Which node accepts all write operations in a replica set? Easy
A. Primary
B. Secondary
C. Arbiter
D. All nodes
Answer: A. Primary
39. What is the purpose of an arbiter in a replica set? Medium
A. To store data
B. To break election ties
C. To improve read performance
D. To encrypt data
Answer: B. To break election ties
40. Which command initializes a replica set? Hard
A. rs.initiate()
B. rs.start()
C. rs.create()
D. rs.new()
Answer: A. rs.initiate()

9. Sharding

41. What is sharding in MongoDB? Medium
A. A backup strategy
B. A method for horizontal scaling
C. A type of index
D. A security feature
Answer: B. A method for horizontal scaling
42. Which component routes queries to the correct shard? Medium
A. mongod
B. mongos
C. config server
D. shard server
Answer: B. mongos (the query router)
43. What is a shard key? Easy
A. A unique identifier for documents
B. A field used to distribute data across shards
C. A password for sharded clusters
D. An encryption key
Answer: B. A field used to distribute data across shards
44. Which sharding strategy divides data into contiguous ranges? Medium
A. Hashed sharding
B. Range sharding
C. Zoned sharding
D. Partition sharding
Answer: B. Range sharding
45. Which command enables sharding for a database? Hard
A. sh.enableSharding()
B. db.enableSharding()
C. mongos --enableSharding
D. sh.startSharding()
Answer: A. sh.enableSharding()

10. Security

46. Which authentication mechanism is recommended for MongoDB? Medium
A. SCRAM-SHA-1
B. SCRAM-SHA-256
C. LDAP
D. Kerberos
Answer: B. SCRAM-SHA-256 (default since MongoDB 4.0)
47. Which role provides full administrative access? Easy
A. dbAdmin
B. root
C. admin
D. superuser
Answer: B. root
48. Which command creates a new user? Medium
A. db.addUser()
B. db.createUser()
C. db.newUser()
D. db.insertUser()
Answer: B. db.createUser()
49. What is TLS/SSL used for in MongoDB? Medium
A. Encrypting data at rest
B. Encrypting client-server communications
C. Encrypting individual documents
D. All of the above
Answer: B. Encrypting client-server communications
50. Which feature provides field-level encryption? Hard
A. TDE (Transparent Data Encryption)
B. Client-Side Field Level Encryption
C. Database Encryption
D. Document Encryption
Answer: B. Client-Side Field Level Encryption

11. Performance

51. Which method explains query execution? Easy
A. db.collection.explain()
B. db.collection.analyze()
C. db.collection.performance()
D. db.collection.stats()
Answer: A. db.collection.explain()
52. Which tool monitors MongoDB performance? Easy
A. mongotop
B. mongostat
C. MongoDB Atlas
D. All of the above
Answer: D. All of the above
53. Which index type supports text search? Medium
A. Single field
B. Compound
C. Text
D. Hashed
Answer: C. Text
54. What is covered by the profiler in MongoDB? Medium
A. Slow queries
B. All queries
C. Write operations
D. Configurable based on profiling level
Answer: D. Configurable based on profiling level
55. Which command flushes all pending writes to disk? Hard
A. db.fsyncLock()
B. db.fsyncUnlock()
C. db.runCommand({fsync: 1})
D. db.flush()
Answer: C. db.runCommand({fsync: 1})

12. Transactions

56. Since which version does MongoDB support multi-document ACID transactions? Medium
A. 3.2
B. 3.6
C. 4.0
D. 4.2
Answer: C. 4.0 (for replica sets, 4.2 added sharded cluster support)
57. Which method starts a transaction in MongoDB? Medium
A. session.startTransaction()
B. db.beginTransaction()
C. Mongo.startTransaction()
D. transaction.start()
Answer: A. session.startTransaction()
58. Which method commits a transaction? Easy
A. transaction.commit()
B. session.commitTransaction()
C. db.commit()
D. Mongo.commit()
Answer: B. session.commitTransaction()
59. What is the default transaction timeout in MongoDB? Medium
A. 30 seconds
B. 60 seconds
C. 5 minutes
D. No default timeout
Answer: B. 60 seconds
60. Which method aborts a transaction? Easy
A. transaction.abort()
B. session.abortTransaction()
C. db.rollback()
D. Mongo.cancel()
Answer: B. session.abortTransaction()

More MongoDB Resources

MongoDB Basics

Learn fundamental MongoDB concepts and commands

View Notes
MongoDB Tricks

Advanced techniques and interview tips

View Tricks