Quick Answer
$set updates specific fields of a document without replacing the whole thing. db.users.updateOne({_id: id}, {$set: {name: "Alice", age: 30}}). Only the specified fields change; other fields stay intact. Without $set, if you pass a plain object MongoDB replaces the entire document (losing all other fields). Always use $set for partial updates.
Answer
$set updates or adds fields without replacing the entire document.
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.
MongoDB interview questions and answers for beginner, junior, mid-level, senior, and expert developers. Perfect for freshers and experienced candidates.