What is the difference between $push and $addToSet?

Junior MongoDB

Answer

$push adds an element to an array even if it already exists. $addToSet adds it only if it is not present, preventing duplicates.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice