MCQs on MongoDB Basics | MongoDB MCQs

MongoDB is a modern NoSQL database designed for scalability, flexibility, and high performance. It uses a document-oriented model, storing data in BSON format, a binary representation of JSON. Developers prefer MongoDB for its powerful query language and seamless CRUD (Create, Read, Update, Delete) operations. Explore its fundamental concepts and gain valuable insights into databases, collections, documents, and query fundamentals with these MCQs.


MongoDB Basics

Q1. What does MongoDB primarily use to store data?

a) Tables
b) Documents
c) Rows
d) Columns

Q2. MongoDB is categorized as which type of database?

a) Relational
b) NoSQL
c) Columnar
d) Hierarchical

Q3. Which of the following best describes MongoDB?

a) Schema-less database
b) Table-based database
c) Fixed-schema database
d) XML-based database

Q4. What is the default port for MongoDB?

a) 8080
b) 27017
c) 3306
d) 1433

Q5. What command is used to check the MongoDB version?

a) show version;
b) db.version();
c) version();
d) mongo --version;


Understanding BSON and JSON

Q6. BSON is a binary representation of:

a) HTML
b) JSON
c) XML
d) YAML

Q7. Which is NOT a valid data type in BSON?

a) ObjectId
b) Decimal
c) Table
d) Binary Data

Q8. What is a key advantage of BSON over JSON?

a) Human-readability
b) Binary storage of data
c) Less data compression
d) Complex syntax

Q9. BSON adds support for which of the following?

a) Extended data types
b) Only integers
c) Nested tables
d) XML parsing

Q10. What is the main purpose of ObjectId in BSON?

a) To store strings
b) Unique identification for documents
c) Reference collections
d) Optimize queries


Databases, Collections, and Documents

Q11. In MongoDB, a collection is analogous to:

a) A column in SQL
b) A row in SQL
c) A table in SQL
d) A database in SQL

Q12. What is the primary role of a database in MongoDB?

a) Storing tables
b) Organizing collections
c) Storing BSON files
d) Managing columns

Q13. A single document in MongoDB is represented as:

a) Array
b) Dictionary-like structure
c) Table
d) Column

Q14. Which command is used to create a new collection?

a) db.createCollection()
b) create collection
c) db.addCollection()
d) create()

Q15. What happens if you insert a document into a collection that doesn’t exist?

a) It throws an error
b) The collection is automatically created
c) The document is rejected
d) Requires explicit permission


CRUD Operations: Insert, Read, Update, Delete

Q16. Which command is used to insert a document in MongoDB?

a) db.insert()
b) db.collection.insertOne()
c) insert()
d) collection.add()

Q17. How do you retrieve all documents in a collection?

a) db.collection.findAll()
b) db.collection.getAll()
c) db.collection.find()
d) findAll()

Q18. To update a single field in a document, you use:

a) $modify
b) $set
c) $update
d) $change

Q19. Which operator is used to delete all documents in a collection?

a) $deleteAll
b) remove()
c) deleteMany({})
d) $dropAll

Q20. What happens when you use deleteMany({}) on a collection?

a) Deletes all documents in the collection
b) Deletes specific documents based on criteria
c) Throws an error
d) Drops the collection


Query Language Fundamentals

Q21. Which method is used to filter documents based on conditions?

a) db.collection.filter()
b) db.collection.find()
c) db.filter()
d) findByCondition()

Q22. To retrieve only specific fields in MongoDB, use:

a) $select
b) db.collection.find({fields})
c) Projection
d) $includeFields

Q23. Which operator is used for AND conditions in MongoDB queries?

a) $and
b) $all
c) $both
d) $combine

Q24. How do you match documents where a field is greater than a value?

a) $gt
b) $gte
c) $greater
d) $greaterThan

Q25. Which operator checks if a field exists in a document?

a) $exists
b) $hasField
c) $fieldExists
d) $contains

Q26. MongoDB supports which type of indexes?

a) Single-field
b) Compound
c) Text
d) All of the above

Q27. Which function drops an index in MongoDB?

a) drop()
b) db.collection.dropIndex()
c) removeIndex()
d) db.collection.remove()

Q28. What does the $in operator do in a query?

a) Matches values equal to one of several specified values
b) Checks if a field exists
c) Matches fields that are not null
d) Filters documents with nested fields

Q29. Which query returns all documents where the “status” field equals “active”?

a) find({status: "active"})
b) db.find("status = active")
c) db.collection.find({status: "active"})
d) db.query({status: "active"})

Q30. Which command is used to sort documents in a query result?

a) db.collection.sortBy()
b) sort({field: order})
c) db.collection.find().sort()
d) orderBy()


Answer Key

QNoAnswer
1b) Documents
2b) NoSQL
3a) Schema-less database
4b) 27017
5b) db.version();
6b) JSON
7c) Table
8b) Binary storage of data
9a) Extended data types
10b) Unique identification for documents
11c) A table in SQL
12b) Organizing collections
13b) Dictionary-like structure
14a) db.createCollection()
15b) The collection is automatically created
16b) db.collection.insertOne()
17c) db.collection.find()
18b) $set
19c) deleteMany({})
20a) Deletes all documents in the collection
21b) db.collection.find()
22c) Projection
23a) $and
24a) $gt
25a) $exists
26d) All of the above
27b) db.collection.dropIndex()
28a) Matches values equal to one of several specified values
29c) db.collection.find({status: "active"})
30c) db.collection.find().sort()

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