$rename
Reference group: Update operator families
What it does
Renames a field.
Syntax
{$rename: { oldName: newName }}
Use case
Migrate a field name.
Important notes
Plan compatibility with old readers and validators.
$rename: practical example
db.users.updateMany({}, { $rename: { "profile.nick": "profile.nickname" } })💡 Explanation
Renames a field.
When to use it
Migrate a field name.
Caution
Plan compatibility with old readers and validators.
Key Takeaways
- Renames a field.
- Typical use: Migrate a field name.