MongoDB Node.
js Associate Developer - Full-Length Mock Test
1. Question 1
What does `updateOne()` return if no documents match the filter?
A) Throws an error
B) Inserts a new document
C) matchedCount = 0, modifiedCount = 0
D) Deletes the closest match
Answer: C) matchedCount = 0, modifiedCount = 0
2. Question 2
Which method ensures atomicity between a read and update in a single operation?
A) find()
B) updateMany()
C) findOneAndUpdate()
D) insertOne()
Answer: C) findOneAndUpdate()
3. Question 3
What does the `returnDocument` option do in `findOneAndUpdate()`?
A) Always returns null
B) Returns the original document
C) Returns the updated document if set to 'after'
D) Throws an error if document not found
Answer: C) Returns the updated document if set to 'after'
4. Question 4
How can you avoid failure of `insertMany()` due to a duplicate `_id`?
A) Use ordered: true
B) Use ordered: false
C) Use insertOne instead
D) Remove _id
Answer: B) Use ordered: false
5. Question 5
Which operator is used to update a nested field in a document?
A) $push
B) $set
C) $addToSet
D) $inc
Answer: B) $set
6. Question 6
Which stage is mandatory in every aggregation pipeline?
A) $match
B) $project
C) $group
D) None
MongoDB Node.js Associate Developer - Full-Length Mock Test
Answer: D) None
7. Question 7
What will `$group: { _id: '$category', count: { $sum: 1 } }` do?
A) Count all categories
B) Create a group by count
C) Count documents per category
D) Group by count field
Answer: C) Count documents per category
8. Question 8
What is the benefit of embedding documents?
A) Decreased performance
B) Normalized data
C) Faster read operations
D) Slower indexing
Answer: C) Faster read operations
9. Question 9
Which indexing strategy supports geospatial queries?
A) 1ds
B) 2dsphere
C) text
D) wildcard
Answer: B) 2dsphere
10. Question 10
What does `useUnifiedTopology: true` do in the MongoClient options?
A) Enables multiple clusters
B) Uses the new Server Discovery and Monitoring engine
C) Disables write concern
D) Forces write locks
Answer: B) Uses the new Server Discovery and Monitoring engine