$unset (Remove Field)

Last updated: 2026-10-09

$unset (Remove Field)

$unset removes the specified field from a document. `{ $unset: { age: '' } }` — the value is a placeholder, often an empty string. Use dotted paths for nested fields; missing fields are silently ignored. Inside array elements $unset sets the value to null rather than removing the element (use $pull to remove).

CategoryUpdate Field
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

{ $unset: { <field>: '' } }

⚙️ Parameters

fieldThe field to remove; dotted paths allowed.
placeholder valueA placeholder value, usually an empty string.

Returns:The update result

▶ Example

Run the commands below in your local mongosh (requires a running mongod):

// $unset: remove the age field
db.users.updateOne(
  { _id: 1 },
  { $unset: { age: '' } }
)

// Remove a nested field
db.users.updateOne(
  { _id: 1 },
  { $unset: { 'address.city': '' } }
)

Output:

// The age and address.city fields are removed from the document

📌 Notes

📚 Related Tutorials

❓ FAQ

QDoes $unset remove array elements?
ANo. Inside arrays it sets the position to null; use $pull to remove elements.
QWhy must $unset carry a value?
AThe value is a placeholder, usually an empty string; any value behaves the same.
QCan $unset remove nested fields?
AYes, via dotted paths.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏