MongoDB Professional Developer Exam Verified
Questions, Correct Answers, and Detailed
Explanations for Computer Science Students||Already
Graded A+
1. Which of the following is the correct way to insert a single
document into a MongoDB collection using the Node.js driver?
A. db.collection.insertMany(doc)
B. db.collection.insertOne(doc)
C. db.collection.save(doc)
D. db.collection.add(doc)
Rationale: insertOne() is the proper method to insert a single
document, while insertMany() is for multiple documents.
2. Which operator is used in MongoDB to find documents where a
field is greater than a specified value?
A. $eq
B. $lt
C. $gt
D. $in
Rationale: $gt stands for "greater than" and filters documents
accordingly.
3. How does MongoDB store related data in a single document?
A. Using joins
B. Using collections
C. Using embedded documents
D. Using foreign keys
,Rationale: MongoDB encourages embedding related data within
documents to reduce the need for joins.
4. Which of the following statements about MongoDB indexes is
true?
A. Indexes are required for all fields
B. Indexes improve query performance
C. Indexes slow down all queries
D. Indexes prevent duplicate documents automatically
Rationale: Indexes allow faster lookups but are not mandatory. They
do not inherently prevent duplicates unless they are unique indexes.
5. How do you update a single field of a document in MongoDB?
A. db.collection.updateOne(filter, {field: value})
B. db.collection.updateOne(filter, {$set: {field: value}})
C. db.collection.replaceOne(filter, {field: value})
D. db.collection.modify(filter, {field: value})
Rationale: $set is used to update specific fields without replacing the
entire document.
6. What is the default _id type in MongoDB documents?
A. String
B. Integer
C. ObjectId
D. UUID
Rationale: MongoDB automatically assigns an ObjectId to the _id
field if none is provided.
,7. Which MongoDB method is used to retrieve all documents in a
collection?
A. findOne()
B. getAll()
C. find()
D. select()
Rationale: find() returns a cursor over all documents that match the
query; an empty query {} retrieves all documents.
8. How can you remove a document from a collection?
A. deleteOne()
B. deleteMany()
C. Both A and B
D. removeDocument()
Rationale: deleteOne() removes a single matching document, while
deleteMany() removes all matching documents.
9. Which aggregation stage is used to filter documents in a
pipeline?
A. $group
B. $project
C. $match
D. $sort
Rationale: $match filters documents at any stage of the aggregation
pipeline.
10. To rename a field in MongoDB during aggregation, which
operator is used?
, A. $rename
B. $project
C. $group
D. $set
Rationale: $project can reshape documents and rename fields in
aggregation pipelines.
11. Which of the following is NOT a valid MongoDB data type?
A. String
B. Char
C. Boolean
D. Date
Rationale: MongoDB does not have a Char type; it uses strings for
textual data.
12. What does the $inc operator do?
A. Sets a field value
B. Increments a numeric field
C. Decrements a numeric field
D. Initializes a counter
Rationale: $inc allows atomic increments or decrements of numeric
fields.
13. Which of the following queries finds documents where status is
"A" or qty is less than 30?
A. {status: "A" && qty: {$lt: 30}}
B. {status: "A" || qty: {$lt: 30}}
Questions, Correct Answers, and Detailed
Explanations for Computer Science Students||Already
Graded A+
1. Which of the following is the correct way to insert a single
document into a MongoDB collection using the Node.js driver?
A. db.collection.insertMany(doc)
B. db.collection.insertOne(doc)
C. db.collection.save(doc)
D. db.collection.add(doc)
Rationale: insertOne() is the proper method to insert a single
document, while insertMany() is for multiple documents.
2. Which operator is used in MongoDB to find documents where a
field is greater than a specified value?
A. $eq
B. $lt
C. $gt
D. $in
Rationale: $gt stands for "greater than" and filters documents
accordingly.
3. How does MongoDB store related data in a single document?
A. Using joins
B. Using collections
C. Using embedded documents
D. Using foreign keys
,Rationale: MongoDB encourages embedding related data within
documents to reduce the need for joins.
4. Which of the following statements about MongoDB indexes is
true?
A. Indexes are required for all fields
B. Indexes improve query performance
C. Indexes slow down all queries
D. Indexes prevent duplicate documents automatically
Rationale: Indexes allow faster lookups but are not mandatory. They
do not inherently prevent duplicates unless they are unique indexes.
5. How do you update a single field of a document in MongoDB?
A. db.collection.updateOne(filter, {field: value})
B. db.collection.updateOne(filter, {$set: {field: value}})
C. db.collection.replaceOne(filter, {field: value})
D. db.collection.modify(filter, {field: value})
Rationale: $set is used to update specific fields without replacing the
entire document.
6. What is the default _id type in MongoDB documents?
A. String
B. Integer
C. ObjectId
D. UUID
Rationale: MongoDB automatically assigns an ObjectId to the _id
field if none is provided.
,7. Which MongoDB method is used to retrieve all documents in a
collection?
A. findOne()
B. getAll()
C. find()
D. select()
Rationale: find() returns a cursor over all documents that match the
query; an empty query {} retrieves all documents.
8. How can you remove a document from a collection?
A. deleteOne()
B. deleteMany()
C. Both A and B
D. removeDocument()
Rationale: deleteOne() removes a single matching document, while
deleteMany() removes all matching documents.
9. Which aggregation stage is used to filter documents in a
pipeline?
A. $group
B. $project
C. $match
D. $sort
Rationale: $match filters documents at any stage of the aggregation
pipeline.
10. To rename a field in MongoDB during aggregation, which
operator is used?
, A. $rename
B. $project
C. $group
D. $set
Rationale: $project can reshape documents and rename fields in
aggregation pipelines.
11. Which of the following is NOT a valid MongoDB data type?
A. String
B. Char
C. Boolean
D. Date
Rationale: MongoDB does not have a Char type; it uses strings for
textual data.
12. What does the $inc operator do?
A. Sets a field value
B. Increments a numeric field
C. Decrements a numeric field
D. Initializes a counter
Rationale: $inc allows atomic increments or decrements of numeric
fields.
13. Which of the following queries finds documents where status is
"A" or qty is less than 30?
A. {status: "A" && qty: {$lt: 30}}
B. {status: "A" || qty: {$lt: 30}}