Debug School

Akanksha
Akanksha

Posted on

Top 30 MongoDB Interview Questions with Answers

1. Which index type is the default in MongoDB?

a) B-tree
b) Hash
c) Text
d) Geospatial
Answer: a) B-tree

2. The find() method in MongoDB returns:

a) The first document that matches the query
b) All documents that match the query
c) The last document that matches the query
d) The count of documents that match the query
Answer: b) All documents that match the querY

3. How can you perform an aggregation in MongoDB?

a) Using the aggregate() method
b) Using the find() method
c) Using the insert() method
d) Using the update() method
Answer: a) Using the aggregate() method

4. The sort() method in MongoDB is used to:

a) Retrieve documents in a random order
b) Sort the documents based on a specified field
c) Delete documents based on a specified field
d) Update documents based on a specified field
Answer: b) Sort the documents based on a specified field

5. What is a TTL index in MongoDB?

a) An index that expires after a specified amount of time
b) An index used for full-text search
c) An index on the "_id" field
d) An index used for geospatial queries
Answer: a) An index that expires after a specified amount of time

6. MongoDB Compass is:

a) A graphical user interface (GUI) for MongoDB
b) A command-line tool for MongoDB
c) A programming language for MongoDB
d) A JavaScript library for MongoDB
Answer: a) A graphical user interface (GUI) for MongoDB

7. What is the default port for MongoDB?

a) 27017
b) 8080
c) 3306
d) 5432
Answer: a) 27017

8. How can you create an index in MongoDB?

a) Using the createIndex() method
b) Using the insert() method
c) Using the update() method
d) Using the find() method
Answer: a) Using the createIndex() method

9. In MongoDB, what does "CRUD" stand for?

a) Create, Read, Update, Delete
b) Connect, Retrieve, Update, Disconnect
c) Copy, Read, Update, Delete
d) Create, Read, Undo, Delete
Answer: a) Create, Read, Update, Delete

10. Which of the following is an example of a MongoDB update operator?

a) $add
b) $subtract
c) $multiply
d) $set
Answer: d) $set

11. What is a capped collection in MongoDB?

a) A collection with a fixed size
b) A collection that cannot be updated
c) A collection with no documents
d) A collection with a unique index
Answer: a) A collection with a fixed size

12. Which of the following is not a type of write concern in MongoDB?

a) "majority"
b) "normal"
c) "w: 1"
d) "unacknowledged"
Answer: b) "normal"

13. What does the term "gridFS" refer to in MongoDB?

a) A specification for storing large files in MongoDB
b) A method for querying data in MongoDB
c) A type of indexing technique in MongoDB
d) A type of data structure in MongoDB
Answer: a) A specification for storing large files in MongoDB

14. What is the purpose of the "db.stats()" command in MongoDB?

a) To display statistics about the database
b) To delete the database
c) To create a new database
d) To display the list of collections in the database
Answer: a) To display statistics about the database

15. How does MongoDB provide high availability?

a) Through replica sets
b) Through sharding
c) Through indexes
d) Through transactions
Answer: a) Through replica sets

16. What is the purpose of the "explain()" method in MongoDB?

a) To display the execution plan of a query
b) To explain the purpose of a collection
c) To explain the structure of a document
d) To explain the purpose of an index
Answer: a) To display the execution plan of a query

17. What is the default storage engine in MongoDB?

a) WiredTiger
b) InnoDB
c) MyISAM
d) RocksDB
Answer: a) WiredTiger

18. How can you drop a collection in MongoDB?

a) Using the deleteCollection() method
b) Using the remove() method
c) Using the drop() method
d) Using the dropCollection() method
Answer: c) Using the drop() method

19. MongoDB uses a protocol called ________ for communication.

a) TCP/IP
b) HTTP
c) WebSocket
d) BSON
Answer: a) TCP/IP

20. Which command is used to start the MongoDB server?

a) start-mongo
b) run-mongo
c) mongod
d) mongo-server
Answer: c) mongod

21. In MongoDB, what does "ACID" stand for?

a) Atomicity, Consistency, Isolation, Durability
b) Aggregation, Concurrency, Isolation, Database
c) Atomicity, Concurrency, Isolation, Durability
d) Aggregation, Consistency, Isolation, Database
Answer: a) Atomicity, Consistency, Isolation, Durability

22. Which operator is used for array manipulation in MongoDB?

a) $push
b) $append
c) $add
d) $update
Answer: a) $push

23. What is the primary role of the MongoDB Query Optimizer?

a) To optimize the performance of queries
b) To enforce security rules
c) To compress the data
d) To maintain indexes
Answer: a) To optimize the performance of queries

24. Which option specifies the number of members that must acknowledge a write operation in a replica set in MongoDB?

a) w
b) j
c) fsync
d) wtimeout
Answer: a) w

25. What is the purpose of the "mongoimport" tool in MongoDB?

a) To import data from a JSON, CSV, or TSV file into MongoDB
b) To import data from another MongoDB database
c) To import data from a SQL database into MongoDB
d) To import data from a URL into MongoDB
Answer: a) To import data from a JSON, CSV, or TSV file into MongoDB

26. What is the primary function of a MongoDB router (mongos)?

a) To route client requests to the appropriate shard in a sharded cluster
b) To perform data validation
c) To manage indexes in a MongoDB database
d) To manage replica sets
Answer: a) To route client requests to the appropriate shard in a sharded cluster

27. Which of the following is an example of a read concern level in MongoDB?

a) "local"
b) "majority"
c) "linearizable"
d) "write"
Answer: a) "local"

28. What does a unique index enforce in MongoDB?

a) Uniqueness of the indexed field or fields
b) Uniqueness of the entire document
c) Uniqueness of the "_id" field
d) Uniqueness of the collection
Answer: a) Uniqueness of the indexed field or fields

29. What is the purpose of the "mongostat" tool in MongoDB?

a) To display statistics about a running MongoDB instance
b) To perform backups in MongoDB
c) To import data into MongoDB
d) To create indexes in MongoDB
Answer: a) To display statistics about a running MongoDB instance

30. Which command is used to connect to a MongoDB server?

a) mongo
b) connect
c) mongod
d) db.connect
Answer: a) mongo

31. What is the purpose of the "journal" in MongoDB?

a) To provide crash recovery and rollback
b) To store log files
c) To compress data
d) To optimize queries
Answer: a) To provide crash recovery and rollback

Top comments (0)