Recall & Review
beginner
What does 'upsert' mean in MongoDB?
Upsert means to update a document if it exists, or insert a new document if it does not exist.
Click to reveal answer
beginner
Which MongoDB method supports upsert behavior?
The updateOne(), updateMany(), and findOneAndUpdate() methods support upsert when you set the option { upsert: true }.
Click to reveal answer
beginner
What option must be set to true to enable upsert in an update operation?
The option 'upsert: true' must be set in the update operation options.
Click to reveal answer
intermediate
If no document matches the filter in an upsert operation, what happens?
A new document is created using the filter and update fields combined, then inserted into the collection.
Click to reveal answer
intermediate
Can upsert cause duplicate documents if the filter is not unique?
Yes, if the filter does not uniquely identify documents, multiple inserts can happen on repeated upserts.
Click to reveal answer
What does setting { upsert: true } do in a MongoDB update operation?
✗ Incorrect
Setting { upsert: true } inserts a new document if no existing document matches the filter.
Which method can perform an upsert in MongoDB?
✗ Incorrect
updateOne() supports upsert when used with { upsert: true } option.
If a document matches the filter in an upsert operation, what happens?
✗ Incorrect
If a document matches, it is updated according to the update instructions.
What happens if the filter in an upsert is not unique?
✗ Incorrect
Non-unique filters can cause multiple inserts if no matching document is found.
Which option is required to perform an upsert with findOneAndUpdate()?
✗ Incorrect
The { upsert: true } option enables upsert behavior in findOneAndUpdate().
Explain how upsert works in MongoDB and when you would use it.
Think about saving time by combining update and insert in one step.
You got /4 concepts.
Describe the risks of using upsert with a non-unique filter.
Consider what happens if MongoDB can't find a unique match.
You got /4 concepts.