15.09.2017 Views

the-magical-marvels-of-mongodb-slides

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Updating a Field Name With $rename<br />

We can use $rename to change field names.<br />

{<br />

"_id": ObjectId(...),<br />

"name": "Love",<br />

"score": 84,<br />

...<br />

}<br />

{<br />

"_id": ObjectId(...),<br />

"name": "Love",<br />

"grade": 84,<br />

...<br />

}<br />

Renamed to<br />

grade!<br />

Renames<br />

specified<br />

field<br />

SHELL<br />

> db.potions.update(<br />

{},<br />

{"$rename": {"score": "grade"}},<br />

{"multi": true}<br />

).<br />

Field to<br />

rename<br />

New field<br />

name

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!