What if you could update your data without ever losing what you already saved?
Why Setting with merge option in Firebase? - Purpose & Use Cases
Imagine you have a big notebook where you write down details about your friends. One day, you want to add a new phone number to a friend's page without erasing the other details you already wrote. But if you just write the new number on a fresh page, you lose all the old notes.
Manually rewriting or updating data without a merge option means you risk deleting important information. It's slow because you have to copy all existing details every time you want to add or change just one thing. Mistakes happen easily, and you might lose data you didn't mean to remove.
The merge option lets you add or update only the parts you want, without touching the rest. It's like adding a sticky note to the notebook page instead of rewriting the whole page. This keeps your data safe and saves time.
db.collection('users').doc('alice').set({phone: '123-4567'})
db.collection('users').doc('alice').set({phone: '123-4567'}, {merge: true})
You can safely update parts of your data anytime without losing anything else, making your app smarter and more reliable.
When a user updates their profile picture but keeps their name and email the same, the merge option updates only the picture without erasing other profile details.
Manual updates risk overwriting and losing data.
Merge option updates only what you want, keeping the rest safe.
This makes data management easier, faster, and less error-prone.