I have a collection, in this collection all my records have, for example, a field named "car". I get a new name for this field from my form and i would like to go through all my records and change only the fields name, without changing the value. I have tried nothing, i can't think any method to do this. This i what i have:
{car:"dodge"}, {car:"ford"}
This i what i would like to get:
{vehicle:"dodge"}, {vehicle:"ford"}
What is the easiest method for this?
The MongoDB docs contain a list of all available update operators. In this case you'd want to use $rename.
In mongojs:
db.coll.update({}, {$rename: {'car': 'vehicle'}}, {multi: true}, callback);